Accessing stored data from native code?
See original GitHub issueYou want to:
From my iOS extension be able to access the data stored by my JavaScript code within the react native app.
Is it possible to call read/write functions from native code?
Exmaple: From javascript
import AsyncStorage from '@react-native-community/async-storage';
await AsyncStorage.setItem('count', 999);
and then, from my native code I want to call what would be equivalent to getItem('count')
to access the stored data. In my case, from the iOS share extension which needs to access this data. Are there any working example of how to do this? Is it even possible?
Details:
Sorry for asking questions that are a bit outside the scope of this module. I know it is supposed to be react native context, but some documentation about how this work behind the scene would be fantastic.
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (7 by maintainers)
Top Results From Across the Web
Access data stored in AsyncStorage from ios native code ...
I've just been faced with the same problem. My solution was to move the code native side. On iOS: #import <React/RCTAsyncLocalStorage.h> ...
Read more >Storing and Getting Data from Async Storage in React Native
In this video, we look at storing and getting data from async storage in react native for our todo app. Part 2. GET...
Read more >A guide to React Native's AsyncStorage - LogRocket Blog
AsyncStorage is an unencrypted and asynchronous data storage system in React Native that allows users to persist data offline.
Read more >Access documents and other files from shared storage
Access documents and other files from shared storage · On this page · Use cases for accessing documents and other files · Create...
Read more >AsyncStorage - React Native
On iOS, AsyncStorage is backed by native code that stores small ... Flushes any pending requests using a single batch call to get...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is possible but requires some knowledge of how native modules work in general. I’m not sure how future-proof this is with regards to the upcoming refactoring work in React Native but this is how you could access it today:
Another (arguably better) way to do this is to implement
RNCAsyncStorageDelegate
as described in this guide. You would have to handle storage yourself but this will allow your extensions to access data directly without knowledge of the bridge or even React Native. We will also strive to have this API stable in the future.@kodeusz: Unfortunately, I’m not as well-versed on the Android side as I’d like to be. From looking at the code, it seems the Android equivalent is ReactContext.getNativeModule(). There’s an example of it being used in UIManagerHelper. Hope that helps 😄