Home > Software design >  AsyncStorage getitem giveing error in useffect in react native
AsyncStorage getitem giveing error in useffect in react native

Time:01-03

AsyncStorage.getItem is giving this error in react native when added in useeffect what am i doing wrong here can anyone pls help me understand the error

export default function Pregent_login(props) {
  const [first, setfirst] = useState();
  useEffect(() => {
    console.log('route.params ==>', props.route.params);

     const value = AsyncStorage.getItem('token');
     setfirst(value);
  }, []);

enter image description here

CodePudding user response:

Check the below code:

export default function Pregent_login(props) {
  const [first, setfirst] = useState();
  useEffect(() => {
    console.log('route.params ==>', props.route.params);

      AsyncStorage.getItem('token').then(token => {
        setfirst(token);
      })
  }, []);

CodePudding user response:

Please try using this way

AsyncStorage.getItem('token').then(token => {
  // again, the rest of your function should be in this block
})

More details Here

  • Related