Closed si-acus closed 6 years ago
Here is an example from their documentation for ES6:
import { createStore, combineReducers } from 'redux';
import { reducer as formReducer } from 'redux-form';
const reducers = {
// ... your other reducers here ...
form: formReducer
};
const reducer = combineReducers(reducers);
const store = createStore(reducer);
You would add the necessary lines here: https://github.com/jimmylee/next-postgres/blob/master/common/store.js
I hope this helps :-) thanks for checking the repo out.
i was try it but other errors appear.
Unexpected keys "post", "users", "posts", "comments", "isAuthenticated", "viewer" found in preloadedState argument passed to createStore. Expected to find one of the known reducer keys instead: "form". Unexpected keys will be ignored.
TypeError: Cannot read property 'length' of undefined
how to move own reducer from root,
const mergeLogoutState = state => {
return { ...state, isAuthenticated: false, viewer: undefined };
};
const myReducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
case 'UPDATE_STORE_KEYS':
return mergeUpdatedKeys(action.data, state);
case 'VIEWER_AUTHENTICATED':
return mergeAuthState(action, state);
case 'VIEWER_LOGOUT':
return mergeLogoutState(state);
default:
return state;
}
};
const reducers = {
myReducer,
form: formReducer
};
const reducer = combineReducers(reducers);
export const initStore = initialState => {
return createStore(reducer, initialState, applyMiddleware(thunkMiddleware));
};
thank you for responding quickly :-)
I'm sorry for the delay on my response, I'll try to reproduce your scenario but it should just work out of the box.
i found to solve this, use next-redux-wrapper for get data and for check is authenticatedset getInitialProps in class
static async getInitialProps(ctx) {
return ctx ? { isAuthenticated : ctx.req.isAuthenticated() , currentUser : ctx.req.user }: { isAuthenticated : null}
}
thanks @jimmylee for awesome project
i try to add redux-form, how can i use combineReducers?