little-state-machine: AsyncStorage doesn't work with react-native

I don’t see how this should currently work, since AsyncStorage is async… ?

At least I don’t know how to make it work in my App. It doesn’t restore / or save the data.

Any hints would be helpful. Thank you ❤️

import React from 'react';
import AsyncStorage from '@react-native-community/async-storage';
import {
  StateMachineProvider,
  createStore,
  setStorageType,
} from 'little-state-machine';

import App from './App';

setStorageType(AsyncStorage);

const data: LittleState = {
  xFormData: {},
};

createStore(data);

const AppContainer = () => (
    <StateMachineProvider>
        <App />
    </StateMachineProvider>
);

export default AppContainer;

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

It works very well now 👍

Wow, that was quick… I couldn’t count on that. I already switched my green-field project to React’s new recoil library. But the react-native support is also not really there yet (only with a patch)… I will see how it is going and if necessary switch back again.

The react world is moving way to fast… for my API cache/state I’m going with react-query.

Anyway, I will try your change later today to give you feedback if it works on my side! Thank you very much. 👍

I can not just make this one function async? This functions is also used in other places, which all would need to await the result of it then, which itself would require it to be async. Unfortunately I didn’t see an easy way out here.

can you provide more detail? actually i will give this a try with RN this weekend, last time another user confirmed its working so i moved on, you can move on with redux, i will sort out to make sure this work for RN, this should be very simple task.