Search code examples
react-nativejwttokenasyncstorage

AsyncStorage getitem giving error in useEffect in React Native


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


Solution

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