Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

please upgrade it with hydrate in nextjs #11

Open
to-long opened this issue Jan 2, 2021 · 0 comments
Open

please upgrade it with hydrate in nextjs #11

to-long opened this issue Jan 2, 2021 · 0 comments

Comments

@to-long
Copy link

to-long commented Jan 2, 2021

when working in NextJS, I have to write my own hydrate and reset function, please help to make it more friendly to dev
`
import { rootReducer } from 'fast-redux'
import { createWrapper, HYDRATE } from 'next-redux-wrapper'
import { applyMiddleware, createStore } from 'redux'

import { composeWithDevTools } from 'redux-devtools-extension'
import thunkMiddleware from 'redux-thunk'

export const AppAction = {
RESET_APP: 'RESET_APP'
}

const appReducer = (state: any, action: any) => {
switch (action.type) {
case HYDRATE:
return {
...state, // use previous state
...action.payload // apply delta from hydration
}
case AppAction.RESET_APP:
return {}
default:
return rootReducer(state, action)
}
}

const initStore = () => {
return createStore(appReducer, composeWithDevTools(applyMiddleware(thunkMiddleware)))
}

export const withRedux = (component: React.ReactNode) => createWrapper(initStore).withRedux(component)
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant