jimmylee / next-postgres-sequelize

[OUTDATED] React 16.8.4 + NextJS 8.0.3 + Emotion + Sequelize 5/Postgres + Passport Local Auth + Google App Engine or Heroku Deployment
https://next-postgres.herokuapp.com/
MIT License
181 stars 39 forks source link

how to add redux-form? #4

Closed si-acus closed 6 years ago

si-acus commented 6 years ago

i try to add redux-form, how can i use combineReducers?

jimmylee commented 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.

si-acus commented 6 years ago

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 :-)

jimmylee commented 6 years ago

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.

si-acus commented 6 years ago

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