SlideShare a Scribd company logo
ReactJs : Tutorial-05-State in ReactJs
What is State in React JS?
A state is a JavaScript object similar to props that have data to be used with the reactjs render.
The state data is a private object and is used within components inside a class.
Components as functions
test.jsx
import React from 'react';
import ReactDOM from 'react-dom';
class Hello extends React.Component {
constructor(props) {
super(props);
this.state = {
msg: "Hello, RTDL - Tutorials!"
}
}
render() {
return <h1>{this.state.msg}</h1>;
}
}
export default Hello;
index.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import Hello from './test.jsx';
ReactDOM.render(
<Hello />,
document.getElementById('root')
);

More Related Content

React js t5 - state

  • 1. ReactJs : Tutorial-05-State in ReactJs What is State in React JS? A state is a JavaScript object similar to props that have data to be used with the reactjs render. The state data is a private object and is used within components inside a class. Components as functions test.jsx import React from 'react'; import ReactDOM from 'react-dom'; class Hello extends React.Component { constructor(props) { super(props); this.state = { msg: "Hello, RTDL - Tutorials!" } } render() { return <h1>{this.state.msg}</h1>; } } export default Hello; index.jsx import React from 'react'; import ReactDOM from 'react-dom'; import Hello from './test.jsx'; ReactDOM.render( <Hello />, document.getElementById('root') );