What will happen if you use props in initial state in reactjs?

Answer

If the props on the component are changed without the component being refreshed,
the new prop value will never be displayed because the constructor function will never update the current state of the component.
The initialization of state from props only runs when the component is first created.


class MyComponent extends React.Component {
constructor(props) {
super(props)

this.state = {
record: []
}
}render() {

return <div>{this.props.inputValue}</div>
}
}

All react js Questions

Ask your interview questions on react-js

Write Your comment or Questions if you want the answers on react-js from react-js Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---