Home > Enterprise >  AsyncStorage getitem giving error in useEffect in React Native
AsyncStorage getitem giving error in useEffect in React Native

Time:01-05

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);
  }, []);

simulatore screenshot

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