score:3
Accepted answer
pass down a callback to the child.
const parent = () => {
const [value, setvalue] = usestate('')
return <child setvalue={setvalue}/>
}
...
const child = ({setvalue}) => {
// use setvalue here which will update parent state
}
score:0
you can do many type of solution for this
passing method wich that do setstate to child and call it in there then you can update the state of parent wich gets from props.
const parent = () => { const [value, setvalue] = usestate('') return (); }
const child = ({setvalue}) => {}
do it with redux or another state management libraries .
Source: stackoverflow.com
Related Query
- Update parent state based on props and onClick from child in React
- Pass state as props from parent to child and then update parent from child onSubmit
- Update state on Parent component from input in Child using props and useState Hook
- update react child component's state using props received from an async api call made in the parent component
- Pass state back to parent AND pass other props from parent to child in React
- Can we pass setState as props from one component to other and change parent state from child component in React?
- Passing event and props from child to parent in react
- React update state in parent from child components
- Update child state based on parent state react functional components
- How to update parent state from child component in React + send a paramater
- Update parent state from child component and re-render this child when parent state is update
- How to update parent state and child components props at once (at the same time)
- React How to change state value from child to Parent using useState and useContext
- Update parent component State from child component in react js
- Unable to pass props from parent to child and save it in state of child component
- Props passed from parent to child and setting those props in state does not work immediately
- Update Child state from Parent using Context in React
- React update child component state from parent using getDerivedStateFromProps
- React Router: props aren't passed down when directly accessing the URL of child component. Will I need to use the same state in both parent and child?
- React & TypeScript how pass data from child to parent at onClick via props
- How to pass props or state from parent to child react in this format
- React update child state from parent component
- Set state in React component from props and update when props change?
- How to update state if I have props coming from parent component in React Hooks
- how does react props merge state passed from parent component and redux store
- React js update child state from an event in the parent
- React Updating parent state with API call and then update child
- passing props from parent to child in react class based component
- React - I am passing state from a child to a parent component but the state value is off by one update cycle
- update state of child component from parent component using react hooks
More Query from same tag
- How can I use ref for the same component which is in the loop?
- Remain on same TabPanel after Refresh on React
- Render a react component on a wordpress page
- How to render NotFound Component react-router-config
- How can I test an action with jest if this action has thunk and axios?
- I am getting this error TypeError: Cannot read properties of undefined (reading 'header') , I am trying to middleware to get users data
- Best Way to Render Multiple Paragraph Text read from JSON into React Component
- Using Flow.js with React compound components
- How to set a loading in component with Redux when call API
- Use setState or setProps is more efficient for Reactjs?
- Initiate a Draft.js Editor with unordered list
- admin-on-rest: customizing Edit component
- How to POST and GET from mongoDB express server in react hooks?
- How can I send a request to API with on click of my button in React hooks?
- Why are these divs all aligned differently?
- how to highlight text as per audio on a website in realtime as the audio narrates it
- Rejection (TypeError): Cannot read property 'name' of null
- React.js: Array won't print on screen but console.log() works fine
- Compile error when running app with cordova after installing firebase plugins
- How do I do a simple onClick to change a child component's classname with React Redux?
- Create custom hook without passing props in React with Typescript
- Pushing objects to array in state object. ReactJS
- How to configure nginx request routing
- axios get and promise function
- Call API Every X Seconds in React Function Component
- How can you merge two objects into same property in JavaScript?
- How to pass reference from onClick to open modal
- Accessing 'this' context in iffe
- How can I mock out all the icons in React `@material-ui/icons` using Jest?
- react-select How to hide dropdown menu programmatically when 'no results found' is shown?