setState is having 2 params first is for updating the state and the second is the callback function which only update if this setState is updated and rendered into the DOM.
() => {
this.setState((state, props) => {
return {name: "Abhay"}
}, () => {
return console.log(this.state.name)
})
}
in react key is necessary has it help's it analysis and update what is required, which means it will only update those methods with that specific key else not. if comes for everything from state Objs to .map() methods
with react there and another methods componentDidMount which run after's the render() is ran which means componenDidMount update the renders() after it's render().
- constructor() which create initialstates or state for the application.
- render() renders the UI on the screen.
- ComponentDidMount() method.
- when you are using callback function inside the render() methods that callback function will be created when ever the render() is called and be deleted after the work is done, and if agian is render() is called it will be created again so if the callback isn't dynamic you have create a separate function for it, which will created only once in memory and be used again and again.
- Components render when on mount(), when state changes and when the props changes.