Sunday, May 19, 2024
138
rated 0 times [  141] [ 3]  / answers: 1 / hits: 61702  / 8 Years ago, mon, october 17, 2016, 12:00:00

I am using react-native with react-native-navigation. I would like to reload data when a component is shown. The component is shown when a user clicks on a tab navigation button.



Should I use react life cycle events or is there something in react-native-navigation that can trigger a function when a user navigates back to a component?



I am using redux, I am not sure if that could be used to help?



This issue refers to onDisplay which seems like what I am looking for. However I can't find any official documentation about it - https://github.com/wix/react-native-navigation/issues/130


More From » react-native

 Answers
26

include this as 'callIfBackToThisRoute'...



export default ( props, call ) => {
if( !props.navigation ) throw 'I need props.navigation'
const thisRoute = props.navigation.state.routeName;
props.navigation.addListener(
'willFocus',
payload => {
if( payload.state.routeName == thisRoute) call(props)
}
);
}


and use it inside your component...



componentDidMount() {
const { doIt } = this.props;
doIt()
callIfBackToThisRoute(
this.props,
(props) => doIt()
)
}

[#60368] Friday, October 14, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raveno

Total Points: 453
Total Questions: 92
Total Answers: 92

Location: France
Member since Thu, Oct 27, 2022
2 Years ago
raveno questions
;