Reputation: 5119
What happens to the state of a react component when the component is re-rendered?
Does it remain unaffected, or does it get reset to some 'default' value? Why?
Upvotes: 1
Views: 394
Reputation: 407
Change in the state will re-render with an updated state.
A state can be changed either by user interaction or a life cycle method only.
When a state is changed, only the updated part will be rendered
Upvotes: 0
Reputation: 954
When you refresh the page, components get re-rendered and state get's reset to default value is it because when component re-rendered we have following lifecycle of react that runs
Initialization here react constructor() run and set the state to default value
Mounting
componentWillMount() , componentDidMount()
Updation
componentWillRecieveProps(), shouldComponentUpdate(), componentWillUpdate(),componentDidUpdate()
Unmounting - This run when you are leaving the component
componentWillUnmount()
Upvotes: 1
Reputation: 5119
Upvotes: 0