skip to Main Content

I’m working on a React Native project where I need to persist data locally and later access it from an Android written in Kotlin. What is the recommended approach for achieving this seamless integration between React Native and Kotlin on the Android side?

I wanted to mention that I need to access the persisted info while the app it’s close and I don’t have access to a rectContext

Any advice on best practices, potential libraries, or specific methods to ensure a smooth flow of data between React Native and Kotlin on Android would be greatly appreciated.

Thank you!

2

Answers


  1. Chosen as BEST ANSWER

    I don't know exactly if it's the best option but I've used react-native-async-storage and then I imported it to Kotlin like this:

    import com.reactnativecommunity.asyncstorage.AsyncLocalStorageUtil
    import com.reactnativecommunity.asyncstorage.ReactDatabaseSupplier
    
    val readableDatabase = ReactDatabaseSupplier.getInstance(context).readableDatabase
    try {
    
                val jsonString = AsyncLocalStorageUtil.getItemImpl(readableDatabase, "@UserDetails") // Key
                userDetails = parseUserDetails(jsonString)
    }....
    

  2. I am using recoiljs + react-native-recoil-persist package to achieve that

    https://recoiljs.org/
    https://www.npmjs.com/package/react-native-recoil-persist

    export const AuthState = atom<AuthStateType>({
      key: 'AuthState',
      default: {
        uniqId: `${uuid()}`,
      },
      effects: [ReactNativeRecoilPersist.persistAtom],
    });
    
    
    // using the state
    const [authState, setAuthState] = useRecoilState(AuthState);
    
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search