skip to Main Content

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

2

Answers


  1. Please try using this way

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

    More details Here

    Login or Signup to reply.
  2. 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);
          })
      }, []);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search