I have two components :
- The first one is the parent Component which is a usual React Component.
- The second one is the child which is a functional component.
I want to pass the value of Titles (in the child state) to the parent Component. Here is my code of Child Component:
export default function ChildApp(props) {
const [titles,setTitles] = React.useState("")
return (
<Button title="submit" onPress={()=>setTitles("asma")}/>
);
}
And here is my Parent Component :
this.state = { titles:"foo"}
setTitles = titles => this.setState({ titles })
// i need the value of Titles to be set in state
export default class ParentApp extends Component {
const titles = this.state.titles
<ChildApp titles={titles} setTitles={this.setTitles} />
}
It seems easy to do but it's the first time for me working with functional components.
Can you help me please ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…