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

Redux Toolkit #83

Open
iot-cpars opened this issue Feb 21, 2022 · 3 comments
Open

Redux Toolkit #83

iot-cpars opened this issue Feb 21, 2022 · 3 comments

Comments

@iot-cpars
Copy link

Hi there, this is less of an issue and more of a request.

Could you maybe make an example of how to use this with redux.toolkit and slices?

I tryed getting it working but am rather new to redux.

Thanks a lot..

@Nigel-Skeels
Copy link

I would be interested to see an example of this too.

Thank you

@nimbit-software
Copy link

What i ended up doing is wraping my getServerSideProps with a method that writes my access token into the Redux store and then i can read it out of the store in the prepareHeaders function. That way i can automate the token handling. But maybe there is a better cookie based way

@halfmatthalfcat
Copy link

import { createSlice } from '@reduxjs/toolkit';
import { HYDRATE } from 'next-redux-wrapper';
import { initialRouterState, routerReducer } from 'connected-next-router';

export const routerSlice = createSlice({
  name: 'router',
  initialState: initialRouterState(),
  reducers: {},
  extraReducers: (builder) => {
    builder
      // for next-redux-wrapper hydration
      .addCase(HYDRATE, (state, { payload }) => ({
        ...state,
        ...payload.router,
      }))
      .addDefaultCase(routerReducer);
  },
});

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

4 participants