国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

In React, localstorage.getItem returns null
P粉551084295
P粉551084295 2024-04-05 14:18:19
0
1
2140

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?

P粉551084295
P粉551084295

reply all(1)
P粉948258958

Use useEffect()

import React, {useEffect} from 'react';

const App = () => {

useEffect(() => {
const obj = { a: "xxx", b: "yyy" }
localStorage.setItem('obj', JSON.stringify(obj));
},[])

return (
     
) }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template