Question: Can I generateStore() with extra initialState?
Closed this issue · 2 comments
aceshim commented
Hi, I am trying to initialize drizzle store with my custom initial states
let initialState = {
name: 'jshim',
age: 18,
}
const drizzleStore = generateStore({
drizzleOptions,
// I want to put it like this
initialState,
}
In generateStore() , there is no way to pass down the initialState.
cds-amal commented
Hi @pensivej,
There isn't a way to set an initialState for a contract field. This is calculated from a contract's abi.
Drizzle does, however, support passing custom middle-wares, reducers and sagas to be managed by its redux instance. If this is your use case, you can define the initial state by setting the default state object in the associated reducer.
// Note: todosReducer's initial state will be `[]`
const todosReducer = (state = [], action) => {
if (action.type === TODOS_RECEIVED) {
// update your state
return action.todos
}
return state
}
cds-amal commented
Hi @pensivej. I will close this issue, but please feel free to reopen if you would like to continue the discussion.