当用户决定通过单击“发送”转到下一个屏幕时,我在调用render方法内部的函数或某种可能的方法更新方法时遇到了一个快速问题。
我的目标是在用户点击“发送”箭头转到下一个屏幕时,将原来创建的“ selectedExchange”更改为更新的“ selectedExchange”。
// On Send Functionality
onSend = () => {
const { exchanges } = this.props
// Testing to see if hard coded values get sought out response
// Hard code values work
// this.props.selectExchange updates the selectedExchange
this.props.selectExchange(exchanges.exchanges[0])
this.props.navigation.navigate('selectRecipient', { transition: 'slideToLeft' })
//return ( exchange )
}
// Additional helper method, able to replace the above "this.props.selectExchange()"
// if necessary
updateExchange = (value, exchange) => {
this.props.selectExchange(exchange)
this.setState({ selectedDisplayName: value })
// Render call
render() {
const { navigation, account, exchanges } = this.props
const { selectedExchange } = exchanges
const { status, symbolPriceTicker, dayChangeTicker } = selectedExchange
const loading = status === 'pending' && !symbolPriceTicker && !dayChangeTicker
const avatar = account.profile_img_url ? { uri: account.profile_img_url } : IMAGES.AVATAR
return (
<View style={globalStyles.ROOT}>
<Loading loading={loading} />
<Image style={globalStyles.backgroundImg} source={IMAGES.BACKGROUND} />
<TopArea navigation={navigation} avatar={avatar} />
<ScrollView>
{
exchanges.exchanges.length > 0 &&
exchanges.exchanges.map(exchange => (
<View style={screenStyles.container}>
<ServiceInfo
account={account}
balances={exchange.balances}
displayName={exchange.label}
symbolPriceTicker={symbolPriceTicker}
// onRequest={this.onRequest}
onSend={this.onSend}
/>
...
...
我尝试过的事情:
通过“ onSend = {this.onSend(exchange)}”传递交换道具,以查看我是否可以传递用于更新selectedExchange的必要对象。这不起作用,因为它要求我从onSend返回一些内容。
在各种视图之间直接在JSX中调用helper方法。也没有用,因为它要求我返回某种形式的JSX。
不知道我还能怎么解决这个问题。感谢您的帮助!