Closed Arjun-Aggarwal closed 5 years ago
May be your initial returning state is null where as it must be a object or your reducers are passing a null value instead a object
I am kind of new to this, so can you explain how I might resolve the error. Thanks a lot
could you show your reducer and action structure else it is hard to figure out.
Can a persistor be used without using middleware? Because I'm not using any middleware.
yeah it depends on your code flow basically middlewares are supporters which are made to write code easy and short. and your dispatch(addcustomer) suppose to be in mainapp.js inside render method for your code structure
This is my reducer code:
import {combineReducers} from 'redux'
import {ADD_CUSTOMER, ADD_TRANSACTION} from './actions'
const merge = (prev, next) => Object.assign({}, prev, next)
const customerReducer = (state = [], action) => {
switch(action.type){
case ADD_CUSTOMER:
return [...state, action.payload]
case ADD_TRANSACTION:
return state.forEach(customer => {
if (customer.name === action.payload.name)
{
customer.amount += action.payload.amount
}
})
default:
return state
}
}
const transactionReducer = (state = [], action) => {
switch(action.type){
case ADD_CUSTOMER:
return [...state, action.payload]
case ADD_TRANSACTION:
return merge(state, action.payload)
default:
return state
}
}
const reducer = combineReducers({
customers: customerReducer,
transactions: transactionReducer,
})
export default reducer
and these are my actions:
//action types
export const ADD_STORE_DETAILS = 'ADD_STORE_DETAILS';
//action creators
export const addStoreDetails = details => ({
type: ADD_STORE_DETAILS,
payload: details,
});
Thanks for the help
sorry I posted the wrong actions code. The correct one is this:
// action types
export const ADD_CUSTOMER = 'ADD_CUSTOMER'
export const ADD_TRANSACTION = 'ADD_TRANSACTION'
// action creators
export const addCustomer = newCustomer =>({
type: ADD_CUSTOMER,
payload: newCustomer
})
Hi! Did you resolve the issue? I have the same problem(((
Yeah, I was using snack.expo to work on my app, which does not support react persist. I switched to expo-cli and it started working
thank you very much
I am trying to a use a very basic persistor, but I am getting this error: TypeError: undefined is not an object (evaluating '_react3.PersistGate') Here is my code: This is the main app
This is the store:
Can somebody explain where I am going wrong