score:2
Accepted answer
state initialization is run only once when component is mounted and the props.contact is undefined yet. that is why you got undefined in your render.
you need to add componentdidupdate
lifecycle method if you want to update your child component state based on props
componentdidupdate(prevprop) {
if (this.props.contact !== prevprops.contact) {
this.setstate({ data: this.props.contact });
}
}
the other thing is that if you don't need to change this.props.contact
in your child component, it's way better to use the prop directly instead of setting state which is not gonna change internally.
Source: stackoverflow.com
Related Query
- How to pass object from parent to child class
- How to pass value from a child functional component to parent class component?
- how to pass in a value from child to parent class in react js
- How to pass value from functional child component to class parent component and save value to state?
- How to pass a Json array of objects from a child class component to parent class component in React?
- How to pass function from class parent component to child functional component
- How to properly pass an array from a parent React class component state to a child component written with hooks?
- How to pass updated array object to parent component from child component in reactJs
- How do I pass props from a child class to parent then to a (different) child class?
- How do I pass an object (created by a buttonClick event) from child to parent in react when already using props for a styled button
- How to pass data from child component to its parent in ReactJS?
- React - How to pass `ref` from child to parent component?
- How to pass function as props from functional parent component to child
- React: how to pass props from child to parent to another child?
- How to pass data from parent to child in react.js
- How to pass value from parent component to child component (react)
- How do i pass data up from a child web component to it's direct parent element
- How to pass input value from child to parent component react
- Pass an object from child to parent component in React
- How to make React.js fetch data from api as state and pass this state data from its parent to child component
- How to pass an Array from Child component to Parent component in react I know how to pass from parent t
- How to pass function from parent component to child component with type assingable
- React TS - How to pass props from a parent component to a deeply nested child
- How to pass form values from child component to parent in react
- How to pass input values from a child Form component to the state of its parent component for submission with react hooks?
- How to pass state from parent Component to child component in route (react-route-dom) reactjs
- how to pass input value from child to parent in functional componenent
- Is it possible to pass "this.state" object from child to parent component using function parameters?
- In React, how do a pass a parameter from a child component up to a parent component?
- Need Reactjs help on how to properly pass this function from the parent to child button component
More Query from same tag
- Get oneOf-prop to change className, CSS modules
- Typescript and React: Type 'Element' is not assignable to type 'FunctionComponent<{}>'
- How do I use the anchor tag for the logout in react js
- FIltering data onChange with useQuery not working properly
- Cannot read property 'getAttribute' of undefined - reactjs
- Using paid version of Material UI with React
- how to make <main> 100% height in material ui drawer demo
- React + Typescript: props from `cloneElement` only
- how to give navigation for list in horizontal menu of reactjs
- Understanding how to approach styling in React
- Error while passing an array to a component (React - TypeScript)
- Jest spyOn is not a function
- NextJS/Typescript/Apollo error; property does not exist on type
- How is the implementation different from the Three.js example?
- React custom hook to to log page render start event
- How to embed/render SSRS report in a ReactJS + .Net core Web API application
- How to get React to resolve index.ts as root of folder?
- How to pass the specific element to function in react
- React Modal I want to be able to scroll a modal when it is vertically long
- ReactJS auth redirect before application loads
- Unexpected token, expected "," while looping through objects
- How to fetch data from complex array objects structures?
- "React" how to pass event to adjacent component
- Creating like button using firestore and useEffect/UseState is causing a loop
- Tried to get frame for out of range index NaN (realtime database)
- React DatePicker calendar showing behind table head
- Can I declare props type for a functional UI component?
- How to Redirect to an external URL while sending formData with POST request via fetch() in ReactJS?
- Detect bottom of page to fetch more data in react
- How to pass dynamic values to ReactJS JSS?