This is the seventh part of the video series on React JS.
We discuss the basics of state in React JS. State represents the data model of a component. It’s bound to the UI. Technically, it’s just JSON data.
The example used in the video is given below
<html> <head> <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script> <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script> <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> </head> <body> <div id="root"></div> <script type="text/jsx"> class Sample extends React.Component { constructor(props) { super(props); this.state = { currentTime: new Date() }; } render() { return (<div> <h1>Time now: {this.state.currentTime.toString()}</h1> </div>); } } ReactDOM.render(<Sample/>, document.getElementById("root")); </script> </body> </html>
You can find the video here.
Read and watch the other parts here.
1. | Hello ReactJS without JSX |
2. | Hello ReactJS with JSX |
3. | Let’s play with JSX – Part I |
4. | Let’s play with JSX – Part II |
5. | Creating Components – Part I |
6. | Creating Components – Part II |