Answers for "Get LocalStorage from WebView react native"

0

Get LocalStorage from WebView react native

import { WebView } from 'react-native-webview';

const INJECTED_JAVASCRIPT = `(function() {
  const tokenLocalStorage = window.localStorage.getItem('token');
  window.ReactNativeWebView.postMessage(tokenLocalStorage);
})();`;

export default function App() {
  const onMessage = (payload) => {
    console.log('payload', payload);
  };

  return (
    <View style={styles.container}>
      <StatusBar style="auto" />
      <WebView
        source={{ uri: 'https://somewebsite.com/login' }}
        injectedJavaScript={INJECTED_JAVASCRIPT}
        onMessage={onMessage}
      />
    </View>
  );
}
Posted by: Guest on April-08-2021

Code answers related to "Get LocalStorage from WebView react native"

Code answers related to "Javascript"

Browse Popular Code Answers by Language