get localstorage from webview react native

Solutions on MaxInterview for get localstorage from webview react native by the best coders in the world

showing results for - "get localstorage from webview react native"
Jakob
21 Jan 2016
1import { WebView } from 'react-native-webview';
2
3const INJECTED_JAVASCRIPT = `(function() {
4  const tokenLocalStorage = window.localStorage.getItem('token');
5  window.ReactNativeWebView.postMessage(tokenLocalStorage);
6})();`;
7
8export default function App() {
9  const onMessage = (payload) => {
10    console.log('payload', payload);
11  };
12
13  return (
14    <View style={styles.container}>
15      <StatusBar style="auto" />
16      <WebView
17        source={{ uri: 'https://somewebsite.com/login' }}
18        injectedJavaScript={INJECTED_JAVASCRIPT}
19        onMessage={onMessage}
20      />
21    </View>
22  );
23}
24