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

Configuration with redux-toolkit #124

Open
michaelkoelle opened this issue Dec 21, 2021 · 4 comments
Open

Configuration with redux-toolkit #124

michaelkoelle opened this issue Dec 21, 2021 · 4 comments

Comments

@michaelkoelle
Copy link

How do i configure immutability with redux-toolkit which uses ImmerJS?

@aohua
Copy link
Owner

aohua commented Feb 9, 2022

Hi @koellemichael, I haven't tried using redux-state-sync with ImmerJS yet, will try setup an example when I got time. PR is welcome, if you wanna try setup an example for redux-toolkit

@untitledlt
Copy link

@aohua any updates on this?

@michaelkoelle
Copy link
Author

I found a workaround for now. I think it might actually be a problem on the redux-toolkit side. Somehow redux-toolkit uses the wrong identifier if the reducers are written like this:

reducers: {
    booksAddOne: adapter.addOne,
    ...
  },

I also tried to specify the identifier using the selectId option in the adapter, but still didn't work. However, if you extract the state and action and pass it explicitly it works:

reducers: {
    booksAddOne: (state, action) => adapter.addOne(state, action.payload),
    ...
  },

Hope that it works for you, too!

@yqkqknct
Copy link

yqkqknct commented Aug 1, 2023

I found a workaround for now. I think it might actually be a problem on the redux-toolkit side. Somehow redux-toolkit uses the wrong identifier if the reducers are written like this:

reducers: {
    booksAddOne: adapter.addOne,
    ...
  },

I also tried to specify the identifier using the selectId option in the adapter, but still didn't work. However, if you extract the state and action and pass it explicitly it works:

reducers: {
    booksAddOne: (state, action) => adapter.addOne(state, action.payload),
    ...
  },

Hope that it works for you, too!

For anyone who came across this, this is due to redux toolkit's adapter checking whether the action is FSA or not (https://github.com/reduxjs/redux-toolkit/blob/e45425128d3c3168c7daa71e5f38f5151234cb8d/packages/toolkit/src/entities/state_adapter.ts#L34 ).

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