Answer the question
In order to leave comments, you need to log in
How to pass props between child functional components in React?
Good afternoon, there is a parent component App and two child components Header and Main how to pass props from header to main????
Answer the question
In order to leave comments, you need to log in
It can be like this:
export default Header = ({ setProp }) => {
return (
<button onClick={() => setProp('hello')}>Ok</button>
)
}
export default Main = ({ prop }) => {
return (
<div>{prop}</div>
)
}
export default App = () => {
const [mainProp, setMainProp] = useState('');
return (
<>
<Header setProp={setMainProp} />
<Main prop={mainProp}/>
</>
)
}
create it in App and then pass it to the children, otherwise useContext can be used. In general, if there was a code, it would be possible to suggest
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question