【问题标题】:React Native Promise <fulfilled>React Native Promise <实现>
【发布时间】:2021-05-26 01:10:49
【问题描述】:

为什么Promise已经兑现了我却拿不到token?

  useFocusEffect(
    React.useCallback(() => {
      const task = InteractionManager.runAfterInteractions(() => 
      {
        const _token =  AsyncStorage.getItem('@token');
        setToken(_token);
        console.log("============================================", _token)
        GetFolderInformation(token, folderId)
        navigation.closeDrawer();
      });
      return () => task.cancel();
    }, [folderId])
  );

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    您需要等待AsyncStorage.getItem('@token')

    useFocusEffect(
        React.useCallback(() => {
          const task = InteractionManager.runAfterInteractions(async () => {
            const _token =  await AsyncStorage.getItem('@token');
            setToken(_token);
            console.log("============================================", _token)
            GetFolderInformation(token, folderId)
            navigation.closeDrawer();
          });
    
          return () => task.cancel();
        }, [folderId])
      );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      • 2018-12-08
      • 2016-07-08
      • 1970-01-01
      • 2022-12-22
      • 1970-01-01
      • 2020-01-03
      相关资源
      最近更新 更多