score:1
in react you just modify state
and dom is updated automatically. your example could look something like below. there is no need to update html directly.
you can also check this introductory tutorial which shows main react concepts.
class reacttypewriter extends react.component {
constructor(props) {
super(props)
this.handleclick = this.handleclick.bind(this);
this.state = { text: ""};
}
handleclick() {
var i = 0;
var txt = 'lorem ipsum dummy text blabla.';
var speed = 50;
let typewriter = () => {
if (i < txt.length) {
this.setstate({ text: txt.substring(0, i++) });
settimeout(typewriter, speed);
}
};
typewriter();
}
render() {
return (
<div>
<h1>typewriter</h1>
<button onclick={this.handleclick}>click me</button>
<p id="demo">{this.state.text}</p>
</div>
)
}
}
reactdom.render(<reacttypewriter />, document.queryselector("#app"))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="app"></div>
Source: stackoverflow.com
Related Query
- how do you use and change innerHTML in react?
- how to use button as link in material-ui react with out underline and change color text?
- How can you use CSS modules together with Typescript, React and Webpack?
- React Native Navigation, how do you pass and use Props between Class Components?
- How do you use an Oauth callback between React and Express?
- How can you pass props and use HOC with React context
- How do you use state variables to make a nested drag and drop in React / Kanban board not working in React
- How do you indicate that a request is loading, and then change the UI once a request is finished, with React Hooks?
- How to use enzyme and jest to detect change React state
- When should you use render and shallow in Enzyme / React tests?
- React Formik : how to use custom onChange and onBlur
- You should not use Route or withRouter() outside a Router when using react-router 4 and styled-component in react
- How to use React with Typescript and SASS
- ReactJS - How to change style and class of react component?
- How do you change the Stepper color on React Material UI?
- How to use drag and drop functionality both columns and rows in my React Table - ReactJS
- How to cache API response and use it later in react & redux?
- How to use vw and vh css with React Native
- How to use Apollo Client + React Router to implement private routes and redirection based on user status?
- How to change name and Icon of Action Column in Material-Table React
- how to import HTML file into React component and use it as a component?
- how to import images via props in react and use the 'import' path
- How do I use React and forms to get an array of checked checkbox values?
- React Typescript how send props and use it in child component
- How to use Django User Groups and Permissions on a React Frontend with Django Rest Framework
- React Navigation 2: How to check previous scene and to disable tab change
- How do you correctly use React.lazy() in Typescript to import a react component with a generic type parameter?
- How do you use an SVG inline in React using Parcel 2?
- How do you use CSS grid layouts with React effectively?
- how and when to call a react component methods after state change from redux
More Query from same tag
- Understanding Redux life cycle, (initial ajax load doesn't work)
- Why is the input type "date" value not updating new values from the input
- Jest - handling base class functions while unit testing
- Unable to set `isSubmitting` with Formik
- Functional Component not receiving props in react
- How to import a default export of webpack entry file from outside?
- Insert Google Adsense after 3rd paragraph
- Material-UI app bar title styling
- How can I get the selected item from List in React?
- TypeError: Cannot read property 'trim' of undefined in ReactJS
- Creating Search functionality in reactJs for Table content
- How to change className based on state and re render it in a functional component
- React/ES6: Trouble Importing a Script
- How to covert Immutable js Data Structure to an use case array without using .toJS() in Redux?
- What to declare react-router argument as in TypeScript
- how to change state by setState in React hooks
- Cannot find name React$Node React Native
- Render attribute or null
- react set new object in array only setting lat item in map
- Cannot find module './assets/photo.jpg' error in React
- How to test react component with onClick function Jest/React testing library
- print the updated version of the array in reactjs
- Delete an item with ReactJS
- How do I add my 'AddToCart' button component in my navbar using react router?
- socket io on client side only runs after I save the file containing the connection
- Reacr-Admin, OData: how to filter a list by nested data
- Element created in constructor not updated when component rerenders
- Access to a several elements through one ref React
- Axios - Uncaught (in promise) Error: Request failed with status code 500
- Combining a ExpressJS Router endpoint with a fetch call to an external enpoint