I am using react-navigation
. I am passing props
from a react-native component
to the modal
from react-navigation
which is opened on a tap.
export default class SomeComp extends Component {
...
render() {
const { navigate } = this.props;
return (
<TouchableOpacity
onPress={navigate("Modal", {data: ..., ...})}
..../>
)
}
}
Inside the modal
I access the goBack()
function which closes the modal
, as well as the props
passed through SomeComp
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>
)
}
}
What I wonder is, whether its possible or not to pass props
down from Modal
to SomeComp
, without using redux
.
In a "normal" react-native parent-child component
I would do that with a simple callback
. However, that does not work here, because the modal
is defined in the router
, hence, completely independent from SomeComp
. Its only called from there...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…