react set state from props code example
Example 1: state and props
What is the Props
Props is short for properties and they are used to pass data between React components. React’s data flow between components is uni-directional
wt is State
which allows components to create and manage their own data
Example 2: lifecycle method react
INITIALIZATION= setup props and state
MOUNTING= constructor->componentWillMount->render->componentDidMount
UPDATE= shouldComponentUpdate->componentWillUpdate->render
->componentDidUpdate
UNMOUNTING= componentWillUnmount
Example 3: react setState
this.setState({
date: new Date()
});
Example 4: component did mmount
componentDidUpdate(prevProps, prevState, snapshot)
Example 5: react change state
this.setState({state to change:value});