score:8
Accepted answer
you need to call a parent function that updates a state in the parent and then pass it as a prop to the first child
parent
..
changeselected = (val) => {
this.setstate({selected: val})
}
render() {
return (
<div>
<firstchild selected={this.state.selected}/>
<secondchild changeselected = {(val)=> {this.changeselected(val)}}/>
</div>
)
}
firstchild:
render() {
console.log(this.props.selected);
}
secondchild:
handleclick = (val) => {
this.props.changeselected(val);
}
Source: stackoverflow.com
Related Query
- How to pass props of one child component to another child component using parent component
- How to call Child function from Parent / Pass Props to a Parent component without using ref methods?
- How can I pass props from one component to another using Link and router in react
- How to set state in parent from one child component and access the state in another child component using react and typescript?
- how to pass props from one component to other in react router that don't have parent child relationship?
- How to pass props from one component to another using optional handling in react hooks
- How to pass function as props from functional parent component to child
- Can we pass setState as props from one component to other and change parent state from child component in React?
- React: how to pass props from child to parent to another child?
- React-Router: pass props from one component to another using link
- How to pass data from one component to another while using API in reactjs
- How to pass a function as props when both Parent and Child component also a functional component?
- React TS - How to pass props from a parent component to a deeply nested child
- React-Router: pass props from one component to another using Navlink
- How to pass a prop back from child to parent in onclick handler and then to another component in React?
- How to pass props from child component to its parent of parent?
- How to pass props onClicked function in one component to another
- How to pass props from one page using a Link(react-router) to a class component
- How can I pass image url from parent component to child component via props [REACT.JS]
- How to get parent props in child component when using styled component in react
- ReactJS How to pass iterated values to child component from parent component using Context API
- How to pass a prop from one component to another when using react router link
- How to pass props from one component to an another component in WeChat Mini-Program
- How do I pass the props from this child component to the parent form
- How to pass an array of data to one component to another component using history.push in ReactJs when fetched using Axios
- How to pass data from one component to another component in onchange using React js
- How to pass props from parent to child using typescript and react?
- How to pass a json array that comes from backend to child component using props and react hooks?
- how can I pass a useState props using TypeScript to a child component
- How to transfer data from one parent component to another parent component in react using router / router params
More Query from same tag
- Best way to dispatch an action client-side upon Sign In using Redux, React, NextAuth
- how add react-loading in react bootstrap table
- Prompt users of unsaved changes if they try navigate to another page in ReactJS
- using insertAdjacentHTML with a React Component
- ReactJS from hash from BrowserRouter
- GraphQL and GatsbyJS: my query isn't working in layouts folder
- React router & Switch - page is not loading after refreshing
- how to handle displayed text in a select?
- How to load assets correctly from webpack-generated NPM package?
- Can I use React-Intl's Built-In Names for Time Periods in my App?
- What kinds of state updates can we defer with `useTransition`?
- adding map function within map function is not displaying any items
- How can i set onchange in a map with React for Switch Buttons from React-Bootstrap?
- Authenticated user shows up in console.log but can't access the object
- React: Trying to set an API JSON response to state object and pass it to component for mapping and rendering
- forEach not working in ReactJs while using data from array
- Unexpected babel build output
- Error while building a drum machine using React
- UseState() throwing a white screen React
- Mapping to React Modal renders all items from array instead of mapping by their ID
- How to return dynamic type depend on the parameter type in function
- Change map position using React Leaflet
- Render user input in a different component in React
- Render HTML string in isomorphic React app
- Drawing sinewave in JS canvas does not do anything
- How do I map across a nested array of objects?
- arrange elements in vertical order
- React component not updating values after element is deleted of specific index
- Array.prototype.includes give me "Argument of type 'string' is not assignable to parameter of type 'never'." error
- Material-ui: outline version of icon