Here is a simple solution using the magic of React's State.
Hope this helps.
import React, { useRef, useState } from 'react'export default function Component () { // This is used to save the reference of your webview, so you can control it const webViewRef = useRef(null); // This state saves whether your WebView can go back const [webViewcanGoBack, setWebViewcanGoBack] = useState(false); const goBack = () => { // Getting the webview reference const webView = webViewRef.current if (webViewcanGoBack) // Do stuff here if your webview can go back else // Do stuff here if your webview can't go back } return ( <WebView source={{ uri: `Your URL` }} ref={webViewRef} javaScriptEnabled={true} onLoadProgress={({ nativeEvent }) => { // This function is called everytime your web view loads a page // and here we change the state of can go back setWebViewcanGoBack(nativeEvent.canGoBack) }} /> )}
Original answerhttps://stackoverflow.com/a/74500469/7823800