asyncstorage

Apollo graphql setting header to authmiddleware not working

两盒软妹~` 提交于 2021-01-07 03:27:00
问题 I am using react-native and apollo client and if I try to set header by jwt stored in AsyncStorage, it seems not working. Other resolvers which doesn't need header works very well. My code is like below. import { ApolloClient } from "apollo-client"; import { InMemoryCache } from "apollo-cache-inmemory"; import { ApolloLink } from "apollo-link"; import { createHttpLink } from "apollo-link-http"; import AsyncStorage from "@react-native-community/async-storage"; const cache = new InMemoryCache()

Sample use case to test Async Storage with Jest-expo?

别等时光非礼了梦想. 提交于 2020-12-10 07:59:09
问题 I have replicated an example to understand the testing of Mock-async-storage for reactjs. Any suggestions for a different approach of testing are welcome. I tried to replicate the use case from this stack overflow page : How to test Async Storage with Jest? but I couldn't figure out how that would fit for my sample case. So I tried the below npm module https://github.com/devmetal/mock-async-storage, but that didn't help either. Code written in Example.test.js import AsyncStorage from '@react

How to properly getItem with AsyncStorage in React Native?

旧时模样 提交于 2020-08-07 07:07:23
问题 My current project require me to store user data locally, So I use the AsyncStorage from react native itself. However I got some issues on how to retrieve already saved data I always get null but somehow the data is saved.. I always get { _45: 0, _81: 0, _65: null, _54: null } and here's my code, which is the simple example from react native documentation AsyncStorage.setItem('baru', 'this is new dude!!'); var b = AsyncStorage.getItem('baru'); console.log(b); 回答1: Reading the docs of

AsyncStorage not resolving or rejecting

末鹿安然 提交于 2020-02-28 05:55:10
问题 I'm trying to get an item from async storage. componentDidMount() { console.log('componentDidMount') AsyncStorage.getItem(STORAGE_KEY) .then(storage => console.log('then', storage)) .catch(err => console.log('catch', err)) } Also trying this way: componentDidMount() { console.log('componentDidMount') AsyncStorage.getItem(STORAGE_KEY, (err, data) => { console.log('data', data); console.log('err', err) }); } But no matter how I do it, the debugger is outputting only the componentDidMount log

How do I set multiple values within Asyncstorage

坚强是说给别人听的谎言 提交于 2020-02-27 07:39:09
问题 How do I set multiple values within Asyncstorge?.Because I'm trying to set token and user_id .These are the server response values. This is how response looks like json { error: 0, data: 'User registered Successfully', userData: { pwd: 'lmlmlm', phone_no: '9898989', user_name: '', status: 1, date: 2018-10-24T07:12:20.656Z }, user_id: 60, token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.' } And in react native I've written like this after user registrtaion. .then((response) => response.json())

React Native AsyncStorage not getting data

匆匆过客 提交于 2020-02-08 07:40:13
问题 I am using following code for storing and retrieving data. But it isn't working as I want. Setting data: async setDataFromApi(token, json) { const {goBack} = this.props.navigation; // Navigation let iext_inf = { token: token, userid: json.data.id, username: json.data.username, image: json.data.profile_picture, }; console.log(iext_inf); try { await AsyncStorage.setItem('iext_inf', JSON.stringify(iext_inf) ); // Stuck here goBack(); } catch (error) { console.log("Error"); } } Getting data:

Is there a way to wait until a function is finished?

*爱你&永不变心* 提交于 2020-01-30 09:41:28
问题 I'm trying to get information (true/false) from AsyncStorage in a function and create a string which is importent to fetch data in the next step. My problem is, the function is not finished until the string is required. I tried many solutions from the internet like async function and await getItem or .done() or .then(), but none worked out for me. The current behaviour is that the console displays first "channel required: " than "channel: channel_id0". 回答1: Aspects in your question are

React-Native AsyncStorage.clear() is failing on IOS

ぃ、小莉子 提交于 2020-01-22 11:37:49
问题 I'm using AsyncStorage.clear() which is working just fine on Android but when run using iOS platform (real device) I'm getting this error and can't find anything online about it. Error: Failed to delete storage directory.Error Domain=NSCocoaErrorDomain Code=4 "“RCTAsyncLocalStorage_V1” couldn’t be removed." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/281A6456-6CB2-47D4-AD04-3EB26A1B9506/Documents/RCTAsyncLocalStorage_V1, NSUserStringVariant=( Remove ), NSUnderlyingError

Waiting for AsyncStorage.getItem()

拜拜、爱过 提交于 2020-01-12 12:52:11
问题 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