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
1 answer

Reducer returned undefined during initialization

I am stuck on this from a long time, and none of the online support till now helped much. I am trying to use immer for immutability in my React-Native app. But the reducer part gives an error saying reducer "count" returned undefined during…
0
votes
2 answers

Modifying private fields with immer.js

I am trying to change a private field from a method of the same class with immer.js But in this case, I need to access not to this, but to the draft instance of same class. This causes an error. import produce from "immer"; export class Test { …
Del Oracle
  • 63
  • 1
  • 3
0
votes
1 answer

Modify state objects on selector

How can I return the tree list from a selector, derived from the flat list in the store? In my nrgx store I have a flat list of objects, using a ngrx/selector I'm converting that flat list into a tree list. I've just implemented immer which is now…
Malcor
  • 2,667
  • 21
  • 29
0
votes
1 answer

findIndex problem with Immer and Redux Starter Kit

I have a redux state that I need to update, it looks like this: [ { date: moment("2019-06-15").toObject(), attendance: [ { name: "Ruben Hensen", membershipNumber: "2084700", …
Ruben Hensen
  • 796
  • 1
  • 9
  • 24
0
votes
0 answers

Rerendering not working on updating app state with immer

I had started building a demo app using React. For immutability, I had started using immer but somehow the render() is not getting invoked on updating component state using produce() of immer library. this.setState(produce( draft => { …
Ajay
  • 4,773
  • 3
  • 23
  • 36
0
votes
2 answers

Immer reducer does not work with Typescript

I have a problem with reducer created by immer.js in TypeScript. I don't understand the following: When I use an object literal {} in initial state immutability works fine but once const byId = (state = {}, action) => produce(state, draft => { …
TomasB
  • 11
  • 4
0
votes
1 answer

Redux change to reflect only on one prop

I have one big object stored on my store holds the API response, whenever I change one change in this object it updates all the components attached to this object and I need it to only update the component that is attached to this only prop not all…
Ahmed Saber
  • 489
  • 1
  • 9
  • 21
0
votes
1 answer

Immer update data using spread

let say I have state in redux const initialState = { age: 0, title: undefined, body: undefined, author: undefined } I want to update it with the newState that I get from my backend and it has exactly the same key (age, title, body, author) so…
coinhndp
  • 2,281
  • 9
  • 33
  • 64
0
votes
1 answer

Test redux reducers with Immer

I recently started using Immer in redux reducers in my react app since I have a lot of nested states in them. (lets avoid the fact the these nesting can be solved with sub reducers). The usage of Immer is clear for me, but once I started to write…
Zoltán Jére
  • 604
  • 5
  • 15
-1
votes
0 answers

Immer access generic object value by key

I'm using immer with generic, here is a minimal example: function foo(record: Record, key: T) { return produce(record, (draftState) => { draftState[key] = true; }); } but this example results in typescript…
deithy
  • 118
  • 6
-1
votes
1 answer

React state doesn't get updated using produce

I have a complex state calculationResults as export interface ICalculationResult { hw: IHwCalculationResult; } export interface IHwCalculationResult { header: IHwCalculationResultHeader; agreements: IAgreementItem[]; } export interface…
Raida Adn
  • 405
  • 1
  • 6
  • 17
-1
votes
1 answer

How to update array of arrays or array of objects in draft of immer without crashing page

I have an array of arrays which is kept on changing on different operations, and I need to update the same in the draft of immer as shown below (Using React with Redux and Immer). return produce(state, draft => { switch (action) { …
-1
votes
1 answer

Why am I getting the error "Cannot assign to read only property"?

I am trying to introduce ngrx into a large legacy angular app (upgraded to Angular 11). The app has a giant model, that holds pretty much all of the data and cannot be adjusted as it is widely used in the company. The idea was to put an instance of…
Taldorr
  • 175
  • 1
  • 4
  • 11
-1
votes
1 answer

React.js updating state vs immutability

Is there any option to add zone without maping it and adding new object into state on first click? https://codesandbox.io/s/charming-ellis-b7e8k?file=/src/App.js:319-324 My wanted behaviour is filling inputs and adding it into state on click. After…
Jakub
  • 11
  • 3
-2
votes
1 answer

Immer not updating the property

I'm using Redux with Immer. This is my code so far: clearMachineState(state, { payload }: ClearMachineStatePayload) { const childrenIds = payload.children.map((child) => child.id); const newMachines =…
Alex Ironside
  • 4,658
  • 11
  • 59
  • 119
1 2 3
14
15