Manoj Kashyam
Manoj Kashyam

Reputation: 178

How state data send to another screen?

my code like this. I get data on first screen and I stored that data in state but I not able to received that data in another screen.

1)

getCharity = (item) => {
        this.setState({updateCharityName: item.charityName})
    }

2)

<TouchableOpacity 
onPress={() => { this.props.navigation.navigate('AppsettingScreen',{UserName:this.state.updateCharityName}),this.getCharity(item)}} 
style={{ backgroundColor: '#ff8787', width: 51, height: 20, borderRadius: 20 }} >
<Text style={{ color: 'white', marginHorizontal: 8, width: 55 }}>Select</Text>
</TouchableOpacity>

second screen:-

1)const data = this.props.navigation.getParam('UserName');
2)<Text style={styles.txtheadvw}>{(JSON.stringify(data))}</Text>

Upvotes: 0

Views: 120

Answers (1)

高鵬翔
高鵬翔

Reputation: 2057

Here have some example. Passing parameters to routes

1.Pass params to a route by putting them in an object as a second parameter to the navigation.navigate function: navigation.navigate('RouteName', { /* params go here */ })

2.Read the params in your screen component: route.params.

Upvotes: 4

Related Questions