Questions tagged [immer.js]

js tool to modify immutable object structures (create new structure by modifying existed one)

Provide Internal DSL for immutable structures cloning and modification.

https://github.com/mweststrate/immer

211 questions
0
votes
0 answers

What are the advantages of immutable data?

What are the advantages of using immutable libraries like immer.js or immutable.js? What is the difference between making changes to a draft of an object or making changes to a duplicate of the object? Are there any performance differences (And…
A. J. Green
  • 93
  • 2
  • 8
0
votes
1 answer

Why redux store doesn't receive an update from immer

Combining reducers export default (injectedReducers = {}) => { return combineReducers({ ...injectedReducers, memoizedStamps: memoizedStampsReducer, // <-- need to write here }); }; Writing an action const mapDispatch = (dispatch) =>…
ezik
  • 451
  • 1
  • 4
  • 15
0
votes
1 answer

Redux-toolkit reducer partially changing state

Hi everyone I have some redux-toolkit issue that I believe comes from immer but cannot be sure. Using createSlice I am creating reducer to manage open/close/move/add of UI tabs. all of the reducers are working properly except the closeTab…
yory100
  • 33
  • 6
0
votes
1 answer

Why is updateQueryData from RTK query not updating my state?

I'm using RTK query and I want to overwrite the state with the result from my transform request. I get my overview of a todos array by calling the getTodosOverview Query. After that I call a updateTodos query and this gives me back a new array with…
Jim Peeters
  • 2,573
  • 9
  • 31
  • 53
0
votes
3 answers

Redux switch case error on reducer ts file

The code is compiled by webpack but I have an error on the browser console. The problem seems to be at the line : 'switch (action.type)' Here is the code : ./reducer import { produce } from 'immer'; import ActionTypeKeys from…
etrix
  • 59
  • 6
0
votes
1 answer

Fetching from a server from within a reducer

I am using react and Immer to make a very simple frontend. The data I need to display is simple nested Json. The json is stored at the top of the tree in a state, and a simple reducer using immer allow editing of the json. I want to add a button…
lethargie
  • 15
  • 3
0
votes
1 answer

Why doesn't the initial value of use immer change?

//PaginationContainer.js function PaginationContainer(props) { const { data = {} } = props; const { endPage = 5, currentPage = 1, nextPage = 6, prevPage = null, pagePerCount = 10, pageBlock = 5, totalData = 0, } =…
yooo
  • 63
  • 5
0
votes
3 answers

How to update state ( initial State ) objects in reducer when using immer?

If have a state of objects payload: export const initialState = { payload: { firstName: 'Mick', lastName: 'Andri', phoneNumber: '651-332-5675', electronicMailAddress: 'mandradi@lake.com', addressLine1:…
Ivan K.
  • 748
  • 7
  • 11
0
votes
1 answer

What is the difference between passing this.state to produce and not? Immer.js

What is the difference between: this.setState(produce((draft) => { draft.name ='name'} and this.setState(produce(this.state, (draft) => { draft.name ='name'} can someone explain me this?
Mykyta
  • 230
  • 2
  • 5
  • 16
0
votes
2 answers

Can you mutate the payload with Redux Toolkit + Immer?

I'm setting up a reducer using Redux Toolkit & Immer using the guide here. Using this we can do immutable updates to the state which look like mutations. However, it's not clear to me if I'm allowed to "mutate" the payload too, as with the example…
Daniel Centore
  • 3,220
  • 1
  • 18
  • 39
0
votes
1 answer

How to use a typed selector inside of a nested function within a React Functional Component?

I'm trying to update user credentials in a React/Redux project with TypeScript. I'm using Firebase so the user credentials are being returned in the .then() block of the signInWithPopup method. Here is the component. It is broken because it is…
0
votes
1 answer

Redux-toolkit deeply nested flatmapped data not updating state

I have deeply nested data, and need to update some deeply nested child. Currently I do it by flatmapping the two upper level lists, then searching in all the possible tasks, and then mutating the task by calling the init function. const tasks =…
supermar10
  • 130
  • 14
0
votes
1 answer

How can I set React component state based on previous state using Immer?

I'm trying to figure out how to set my React component's state based on the previous state, while also using the Immer library to allow for easier immutable state changes. Normally, without Immer, I'd safely access the component's previous state…
Fateh Khalsa
  • 1,326
  • 1
  • 15
  • 19
0
votes
1 answer

How to perform edits to a draft object using Immer.js after promise has resolved without using async/await

I'm trying to make edits to a draft object from Immer that depend on a promise resolving. I understand how to do this with async/await syntax, (see below) import produce from 'immer'; Promise.resolve({ eggs: 0 }).then( produce(async (eggCounter)…
pixatlazaki
  • 572
  • 8
  • 19
0
votes
1 answer

How add new field into reducer using Immer.js?

For example, state = { data: {} } How can I add a new nested field into an object? I cannot set that field, because have an error Cannot read property 'date' of undefined const reducer = produce((draft, action) => { switch (action.type) { …