AsyncStorage:React Native

时间:2017-08-18 08:09:49

标签: session react-native asyncstorage

保存'唯一ID'作为反应原生的会话变量

2 个答案:

答案 0 :(得分:7)

您可以使用AsyncStorage添加唯一ID,如下所示:

   AsyncStorage.setItem('Key Name', uniqueId)

之后,您可以从其他组件中获取:

   AsyncStorage.getItem('Key Name').then((value) => console.log(value))

有关详情,请参阅documentation。我希望这个答案可以帮到你。

答案 1 :(得分:3)

import { AsyncStorage} from 'react-native';
AsyncStorage.getItem('Key Name').then((value) => console.log(value))

我们可以从app的任何组件中获取asyncstorage的值。

使用另一个函数的数量,如merge,remove等。请参阅documentation

相关问题