asyncstorage

Waiting for AsyncStorage.getItem()

徘徊边缘 提交于 2020-01-12 12:51:48
问题 I am using AsyncStorage in my React Native application to store information about the user. The getItem() function is asynchronous and requires me to implement a callback when I want to load data from the storage system. AsyncStorage.getItem("phoneNumber").then((value) => { this.setState({"phoneNumber": value}); }).done(); Because retrieving a value from the storage does not take long, I would like to wait until the operation is complete before continuing execution. Is it possible to load

React Native: How to use Java code to fetch data via React Native async storage

风格不统一 提交于 2020-01-04 02:21:17
问题 Is it possible to fetch data from React Native Async-Storage through the Android-Java code? If it is possible then, how can I use Android-Java code to fetch Async-Storage data (id etcs). My data structure for RN Async Storage are: (id, fname, lname, isactive) What I want to do: I want to use the Java code for Android to connect with RN Async Storage and get the values of the data. eg: id, fname, lname .. etcs. 来源: https://stackoverflow.com/questions/44635641/react-native-how-to-use-java-code

Is AsyncStorage permanent?

故事扮演 提交于 2020-01-04 02:11:09
问题 I am storing my app's auth token in AsyncStorage. It appears that both on Android and iOS (less sure about this one), after long periods of inactivity (~2 weeks), users are logged out. I am sure that it doesn't have to do with the server. Is AsyncStorage permanent? EDIT: Well, that's embarrassing. The problem was on the server, and it wasn't AsyncStorage's fault. 回答1: From the RN docs https://facebook.github.io/react-native/docs/asyncstorage.html On iOS, AsyncStorage is backed by native code

How and where to save the whole redux store using AsyncStorage

心不动则不痛 提交于 2020-01-01 04:16:05
问题 I was wondering if I have to do something like this to save the whole store of my app using AsyncStorage in my react-native app and check if it exists when the app is starting. var store; _loadInitialState = async () => { try { var value = await AsyncStorage.getItem(STORAGE_KEY); if (value !== null){ store = value; console.log('Recovered selection from disk: ' + value); } else { store = configureStore({}); console.log('Initialized with no selection on disk.'); } } catch (error) { console.log(

React Native AsyncStorage not getting the value

会有一股神秘感。 提交于 2019-12-24 23:27:46
问题 constructor(props) { super(props); this.state = { data: '' } ; } componentWillMount = () => AsyncStorage.getItem('restaurants').then((value) => this.setState({data: value})) return ( <View> {this.state.data.map((item) => { return ( <View> <Text> {item.name} </Text> <Text> {item.time} </Text> </View> ) }) } </View> ) I am trying to get the value in the AsyncStorage, but i keep getting the error: undefined is not a function(evaluating 'this.state.data.map). I been searching the similar topic

React Native AsyncStorage [closed]

你。 提交于 2019-12-22 01:24:49
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I want to save houses in an array using AsyncStorage. Each array element represents a house Object. And each house object has a latitude, longitude and a house number. I am not sure how to go about representing this. It seems to me that AsyncStorage is not well-suited for saving

React Native AsyncStorage getItem returns promise not value

僤鯓⒐⒋嵵緔 提交于 2019-12-21 04:42:40
问题 I have a login form and I am able to post my the form values. After a successful POST request, I get authentication token returned from the API. I need to save this token for future reference in local storage. For saving this auth token I am using AsyncStorage. I used AsyncStorage.setItem(STORAGE_KEY, responseData.auth_token); setItem method to save the data. If I console log this by : console.log(AsyncStorage.setItem(STORAGE_KEY)); it returns as promise object like this Promise {_45: 0, _81:

How to Read AsyncStorage on Android Correctly

為{幸葍}努か 提交于 2019-12-17 20:39:37
问题 It seems that it's possible access the AsyncStorage from Android (native); but I still struggling to make this work. In my React Native application, I have something like: Store const config = { ... } export const reducers = { ... user: user } let rootReducer = combineReducers(reducers) let reducer = persistReducer(config, rootReducer) User Reducer export class Actions { ... } const initialState = { first_name: : null, last_name: : null, email: null, addresses: [ { ... } ] } } } export const

React Native AsyncStorage: Cannot resolve promise returned by getItem

不羁岁月 提交于 2019-12-14 02:12:10
问题 I have the following code that should return an item from AsyncStorage. However the item is never read: const key = 'shoppingListItems'; export default class ShoppingListService { static async getItems() { let result = await AsyncStorage.getItem(key); return result; } // ... } And I use it in a component (screen): // ... componentDidMount() { alert(JSON.stringify(ShoppingListService.getItems())); } // ... It always shows me a message with: {"_40":0,"_65":0,"_55":null,"_72":null} How do i get

AsyncStorage.getItem returning promise [duplicate]

℡╲_俬逩灬. 提交于 2019-12-11 21:17:36
问题 This question already has answers here : How do I return the response from an asynchronous call? (36 answers) Closed last year . So I am trying to get data with AsyncStorage.getItem and then pass it to a function in React-native. but when I do that I get this error "data.filter is not a function" from my function. I think that the problem could be that I am not getting the data but insted a promise. Constructor: constructor(props) { super(props) const getSectionData = (dataBlob, sectionId) =>