0

How I can reload a webview to initial source when I click on button from navigator? I can reset a original componet using?

React.useEffect(() => {
     const unsubscribe = navigation.addListener('tabPress', e => {
  
});

Or I can reload the webview on component?

function TabOneNavigator({ navigation }) {
  React.useEffect(() => {
    const unsubscribe = navigation.addListener('tabPress', e => {
      alert('Default behavior prevented');
    });

    return unsubscribe;
  }, [navigation]);

  return (
    <TabOneStack.Navigator>
      <TabOneStack.Screen
        name="Perfil"
        component={TabOneScreen}
        options={{ headerTitle: 'IzyJob' }}
      />
    </TabOneStack.Navigator>
  );
}

my screen

export default class App extends React.Component {
  state = {
    url: 'https://www.google.com'
  };
  render() {
    return <WebView 
    source={{ uri: this.state.url }} 
    style={{ marginTop: 0 }} />;
  }
}

My idea is when page on webview is different of state.url and has a click on tab navigation I reload to initial url

1 Answer 1

2

First create reference for the webview, like given below

<WebView
    ref={(ref) => { this.webview = ref; }}
    source={{ uri: this.state.url }} 
    style={{ marginTop: 0 }} />;

Then call this.webview.reload() where you want, this code will help you to refresh your webview

Sign up to request clarification or add additional context in comments.

2 Comments

how I can use this.webview.reload() in another component? i need use with ref?
create a ref in parent component and pass to webview component and give that ref to webview then you can refresh the webview by calling ref.reload() from parent

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.