redux-zero / redux-zero

A lightweight state container based on Redux

Home Page:https://matheusml1.gitbooks.io/redux-zero-docs/content/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React Native, createStore() from AsyncStorage issue

hossammourad opened this issue · comments

Hello, I'm trying to use the createStore function but get the values of each key from the AsyncStorage in React Native.

import createStore from 'redux-zero';
import { AsyncStorage } from 'react-native';

const getValueFromAsyncStorage = key => {
  AsyncStorage.getItem(key).then(val => {
    return val ? JSON.parse(val) : [];
  });
};

const store = createStore({
  expenses: getValueFromAsyncStorage('expenses'),
  categories: getValueFromAsyncStorage('categories')
});

export default store;

There are values for expenses and categories in AsyncStorage but when I try to console.log store.getState(), the values of each key is a promise.

@hos4m does that help? Can I close this?