Let's understand lifecycle method in this blog
ComponentWillMount is executed before rendering, on both the server and the client side.
ComponentDidMount is executed after the first render only on the client side. This is where AJAX requests and DOM or state updates should occur. This method is also used for integration with other JavaScript frameworks and any functions with delayed execution such as setTimeout or setInterval. We are using it to update the state so we can trigger the other lifecycle methods.
ComponentWillReceiveProps is invoked as soon as the props are updated before another render is called. We triggered it from setNewNumber when we updated the state.
ShouldComponentUpdate should return true or false value. This will determine if the component will be updated or not. This is set to true by default. If you are sure that the component doesn't need to render after state or props are updated, you can return false value.
ComponentWillUpdate is called just before rendering.
ComponentDidUpdate is called just afterrendering.
No comments:
Post a Comment