1
I need to change a state within a function of React navigation, this state will change a behavior in the Component
function TabOneNavigator({navigation}) {
React.useEffect(() => {
const unsubscribe = navigation.addListener('tabPress', e => {
if(global.webview.startUrl != global.webview.props.source.uri){
//aqui eu preciso chamar o metodo resetWebViewToInitialUrl()
//que está no componente
}
});
return unsubscribe;
}, [navigation]);
return (
<TabOneStack.Navigator>
<TabOneStack.Screen
name="Perfil"
component={TabOneScreen}
options={{ headerTitle: 'IzyJob' }}
/>
</TabOneStack.Navigator>
);
}
i am trying to change the state of the component when the React Navigator button is clicked, that is the code of my component
export default class App extends React.Component {
this.state = {
key: 1,
url: 'https://www.google.com'
};
resetWebViewToInitialUrl = () => {
this.setState({
key: this.state.key + 1
});
};
render() {
return <WebView
key={ this.state.key }
ref={(ref) => { global.webview = ref; }}
source={{ uri: this.state.url }}
onNavigationStateChange={this._onNavigationStateChange.bind(this)}
style={{ marginTop: 0 }} />;
}
}
I have tried using props but not enough in the function of Navigator, also tried creating a global but then I can not change the state