【发布时间】:2018-03-29 11:54:12
【问题描述】:
我正在使用react-navigation。我将props从react-native component 传递到modal,从react-navigation 通过水龙头打开。
export default class SomeComp extends Component {
...
render() {
const { navigate } = this.props;
return (
<TouchableOpacity
onPress={navigate("Modal", {data: ..., ...})}
..../>
)
}
}
在modal 内部,我访问了关闭modal 的goBack() 函数,以及通过SomeComp 传递的props
export default class Modal extends Component {
...
render() {
const { data, ... } = this.props.navigation.state.params;
const { goBack } = this.props.navigation;
return (
<View>
<TouchableOpacity
onPress={goBack()}
..../>
<Text>
{data, ...}
</Text>
</View>
)
}
}
我想知道的是,是否有可能将props down 从Modal 传递到SomeComp,没有 使用redux。
在“正常”react-native parent-child component 中,我会使用简单的callback 来做到这一点。但是,这在这里不起作用,因为modal 是在router 中定义的,因此完全独立于SomeComp。它只是从那里调用...
【问题讨论】:
标签: javascript react-native router react-navigation