score:2
Accepted answer
in your case you have to use componentdidmount
because when edititem
state is set, then you are unmounting model
component and remounting it with content
prop. so in that case componentwillrecceiveprops
will not get fired but componentdidmount
will get fired. so move your componentwillreceiveprops
logic to componentdidmount
like
componentdidmount(){
console.log(this.props) // never fired..why??
let {dish, ingredients} = this.props.content
this.setstate({
dish:dish, ingredients:ingredients
})
}
Source: stackoverflow.com
Related Query
- How to update modal component with new props
- How can I safely set new state of a component when props change with useEffect (for an edit form modal component)?
- How do I update my React app with new props after an AJAX call?
- How to render component again at the top level with the new props in React 0.14
- How to redirect to new component with props on submit using React
- How to test if a component is rendered with the right props when using react-testing-library?
- How to pass props to Screen component with a tab navigator?
- How to update ReactJS component based on URL / path with React-Router
- How do I pass props a component rendered with Enzyme.js?
- How to update props of React Component rendered using ReactDOM.render()
- Why does calling useState's setter with the same value subsequently trigger a component update even if the old state equals the new state?
- how to change image src using props with styled component and react
- How can I add a new property to Component in _app.tsx in Next.js with Typescript?
- How to load child component with props on first render with React Hooks
- How to create new elements with React mapping props
- How to add new props dynamically to the component using navigator in React Native
- How to update state of a component with value from reducer state in react-redux?
- p5.js and React: how to update a sketch inside a component when one of the component's props is updated
- How to update list of items with Infinite scroll when new item added
- How to update React Component props during unit tests?
- React: How to update fetch with new query
- How to update a component after updating props react
- How to force React (functional component using hooks) to create a new component from scratch on props change?
- How to update State Hook with onClick listener on React Component Instance
- How to send props to a component in react with conditional?
- how to update parent's state from child component along with passing some information from child
- How to pass styles via props with styled components without having to create the component inside the component
- How to destructure props in stateless component (react) with default values into a variable and apply spread operator with that variable in JSX?
- D3.js how to update chart when with new data
- How to deal with component reference variables and props in React 0.12+?
More Query from same tag
- How to access create-react-app run in a docker container?
- Using Microsoft Authentication Library MSAL with PnPjs
- How can I get "this" into scope in a ReactJS ES2015 async function?
- How to improve this JS code to look more elegant
- CSS styling in order to properly align img's the way I want them to on my page?
- Encapsulate URL to fix 404 error on react js application page when we reload/refresh
- How to copy nested object properties using spread operator
- Typescript: Type 'X' provides no match for the signature '(prevState: undefined): undefined'
- eslint: Component Definition is missing displayName
- added data don't update automatically in useEffect() Need refresh browser to get the last addition
- React how to keep rendered components
- How would I wrap a div that is repeating in a .map method
- Google OAuth via gapi.signin2.render button not hitting callbacks in react app
- Throw object instead of returning string
- How to loop over JSON data from external file in ReactJS?
- Cannot find module issue with imports-loader when testing with Jest
- Create an Array of Object from another Array of Object with dummy object
- ReactJS show loader on child component update
- How to render the elements before to filter elements with ReactJS?
- Adapting a 'custom' component to redux-forms?
- lock/prevent close of menu reactjs
- How to get first error while using yup to validate object schema
- How to update a specific field in an array that matches a query in a Mongodb document?
- how can i focus only one button at a time and not several at the same time?
- null values for instead of date causes the browser to crash while using chart js
- How can I merge ...object and return value of function call in setState(react-hook)?
- npm start webpack issue?
- Dropdown not expanding even after having values
- React Hook useCallback not updating State value
- Why i can't use map on redux useSelector?