Javascript 在本机反应中擦除 AsyncStorage

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39345809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 22:30:23  来源:igfitidea点击:

Wipe AsyncStorage in react native

javascriptreact-nativereduxasyncstorage

提问by jsdario

I notice that I am wasting a certain amount of time debugging reduxactions that I am persisting to AsyncStoragein react-nativethanks to redux-persist. Sometimes I'd just like to wipe AsyncStorage to save some development time and try with fresh data.

我注意到,由于redux-persist,我正在浪费一定的时间来调试我在react-native 中坚持使用的redux操作。有时我只想擦除 AsyncStorage 以节省一些开发时间并尝试使用新数据。AsyncStorage

EDIT: Best case the solution should work on simulators and real devices, iOS and Android. Maybe there are different work arounds for different platforms.

编辑:最好的情况下,解决方案应该适用于模拟器和真实设备、iOS 和 Android。也许不同平台有不同的解决方法。

Thanks

谢谢

采纳答案by Tony Vincent

Try using clear()function which erases all AsyncStoragefor all clients, libraries, etc

尝试使用清除AsyncStorage所有客户端、库等的clear()函数

回答by hzak

clearAsyncStorage = async() => {
    AsyncStorage.clear();
}

This function can be applied anywhere on the code base to clear AsyncStorage. For example, here is how it can be called on a <Button>component.

此函数可以应用于代码库上的任何地方以清除AsyncStorage. 例如,这里是如何在<Button>组件上调用它。

<Button onPress={this.clearAsyncStorage}>
  <Text>Clear Async Storage</Text>
</Button>

回答by Alister

You can clear AsyncStorage easily without touching your source code. Using react native debugger; and in the devtools console type

您可以轻松清除 AsyncStorage,而无需接触源代码。使用本机调试器;并在 devtools 控制台类型中

$reactNative.AsyncStorage.clear();

or to call it in RN's normal debugger with clear()you can put this in...

或者在 RN 的普通调试器中调用它,clear()你可以把它放在......

if (__DEV__) {
   global.clear = () => {
     AsyncStorage.clear().then(() => console.log('Cleared'))
   }
}

回答by Tom A

redux-persistcomes with a purge()callback. You can call that in a debug menu somewhere if you choose.

redux-persist带有purge()回调。如果您愿意,您可以在某个地方的调试菜单中调用它。