React Bala
React Bala

Reputation: 111

react native How to get child component const value to parent screen component

I have one text input in my child component and I want to get the text input data to my parent screen. I want to pass the data to one component to another component.

Upvotes: 0

Views: 407

Answers (1)

Gaurav Roy
Gaurav Roy

Reputation: 12195

You have 2 components parent and child suppose , then it would be like

In render of Parent , basically you are passing a callback function to child

textChange = (value) => {
this.setState({newText:value});
}

render(){
return(
<Child onTextInput={this.textChange} />
)
}

and in child's render:

render(){
return(
<TextInput  onChangeText={e => this.props.onTextInput(e)}
)
}

Hope it helps.

Upvotes: 1

Related Questions