score:1
Accepted answer
you need to use the componentwillreceiveprops
lifecycle method it will get called whenever any change happens to props values so at that time you need to update the state value.
use this:
componentwillreceiveprops(newprops){
this.setstate(newprops.contactinfo);
}
componentwillreceiveprops() is invoked before a mounted component receives new props. if you need to update the state in response to prop changes (for example, to reset it), you may compare this.props and nextprops and perform state transitions using this.setstate() in this method.
Source: stackoverflow.com
Related Query
- React Redux Proper way of iterating over data on init
- ReactJs : What is the proper way of accessing the state data in the root component where the link between React and Redux has been implemented?
- Most efficient way of rendering JSX elements when iterating on array of data in React
- Whats the proper way to have a form submit data in a stateless react component?
- Proper way to render content without flickering ? React + Redux + TS
- Proper Way in Fetching Initial Data in React Boilerplate Container
- React and Redux: Proper Way To Store Loading State in Redux
- ReactJS - Proper way to fetch data from redux and load form
- Best way to map over asynchronous data in React
- Proper way to wait for async data to store in state in React or React Native
- Proper way to send data and delete rows in form react
- Is there a way to cache data coming from redux connect in React function component with using useRef()?
- What is the proper way of updating this Redux store state in React app
- Proper way to delete particular property from main state of Redux which uses combineReducers - React Redux
- What is the best way to store data with React Redux but by condition?
- Proper way to include lists and other external data inside a TypeScript React App
- Save data in localstorage after call proper action. React & Redux
- In the process of React / Redux development, what is the proper way to install bootstrap?
- What is the best way to access redux store outside a react component?
- React + Redux - What's the best way to handle CRUD in a form component?
- Proper way of using React hooks + WebSockets
- Where do I fetch initial data from server in a React Redux app?
- Is there a right way to pass data into a React component from the HTML page?
- Proper way to navigate with React Native, Redux, and Navigator
- Is there any proper way to integrate d3.js graphics into Facebook React application?
- How to cache fetched data in react without redux
- Proper way of using WebSockets with React Native
- Async data flow in React App with Redux + ReactRouter?
- Cons of next.js over create react app + redux + ssr
- What's the proper way of binding touchstart on React JS?
More Query from same tag
- App working fine on localhost but doesn't loads on netlify?
- Recharts: LabelList content prop not working
- add icon to header navBar (I am not getting that how to add icon on the most left in my NavBar)
- synchronous operation in componentDidMount()
- Redux form - passing a function as a property to a field array gives undefined
- Why is async await very slow?
- How to implement an input type number with controllers (with redux form)
- Broken Images in New React-Router-Dom V6
- How to structure a component using React Hooks with an object that uses the DOM directly? (such as OpenLayers)?)
- React - show a component until it is completely ready
- change react Build cofiguration
- Is it possible to change react props
- How to change the style of the navbar on scrolling?
- Update inside React useState setter being called twice
- Is there a way to know if a specific prop was updated without using state in React?
- three.js OBJLoader not loading in react
- Redux react not setting the value after action/reducer call
- Adding button inside Ant-design table column
- How to filter data in react?
- Uncaught TypeError: Cannot read properties of undefined (reading 'companyName') JS Objects
- How to filter request to Firebase realtime database
- Circular definition of import alias 'theme'
- Not able to figure out why Docker build command is not working
- React render pasted html as tags, not string
- How to display error to the user in MERN stack
- 404 Not Found nginx React
- React input minLength onKeyDown
- How to get React setState to re-render for Foundation 6 Reveal (Modal)?
- how to get select tab in lib tabs
- How to change setState in (then) so as not to get an error?