index.js:
import React from 'react'; import ReactDOM from 'react-dom/client'; import './index.css'; import App from './App'; import reportWebVitals from './reportWebVitals'; const root = ReactDOM.createRoot(document.getElementById('root')); const obj = { a: "xxx", b: "yyy" } localStorage.setItem('obj', JSON.stringify(obj)); root.render( <React.StrictMode> <App /> </React.StrictMode> );
Client.js:
let settings = JSON.parse(localStorage.getItem('obj')); const oktaAuth = new OktaAuth({ issuer: settings['a'], clientId: settings['b'], redirectUri: window.location.origin + '/login/callback', logoutUrl: window.location.origin + '/login', // pkce: false });
I imported the client in App, it seems that localStorage should set Item before client.js is run. But my localStrorage.getItem('obj') is null. Does anyone know why?
Use useEffect()