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

NgRx-etc: Cannot assign to read only property 'Property' of object '[Object]'

So i have this in my reducer: export interface PersonState { person: Person; } which has an array of relatives inside and i'm trying to update it with this: mutableOn(PersonActions.addRelatives, (state, { relatives }) => { const person =…
0
votes
1 answer

Return array value from produce function | immer.js

I am using immer.js to perform operations on arrays in the state. Arrays: basicRecipe and recipeBasicRecipe. I am modifying the draft.basicRecipe in the produce function. My objective is to return the updated "draft.basicRecipe" value and store the…
user13909231
0
votes
1 answer

TypeError: Object is not iterable when I using ContexAPI in Reactjs

I'm trying to share data between component using ContextAPI in ReactJs. But I have a stuck when using it. This err is : "TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator))" at line 7: *const [state, dispatch] =…
0
votes
2 answers

Update one of the objects in array, in an immutable way with immer.js

Say I have some initial state like const initialState = { post: { comments: { {0: {id:'1',name:'myname',statusdata: false}}, {1: {id:'2',name:'yourname',statusdata: true}}, }, }; And I want add to data…
bokino12
  • 317
  • 5
  • 13
0
votes
1 answer

react, how to not mutate state without deepcloning?

You have data stored in a state (possibly redux state) and You are using formik to modify your data. In code, let { data } = props // from redux state // suppose data is somewhat deep like // data = { // p1: { // p11: { // …
eugene
  • 39,839
  • 68
  • 255
  • 489
0
votes
1 answer

Use memoized value in immer.js draft

I have a complex object (graph - nodes and edges) in state which I update with immer.js. I memoize some computations on the object (e.g. node adjacency list) using memoize-one library. However this is a problem since the draft is not identical with…
amik
  • 5,613
  • 3
  • 37
  • 62
0
votes
0 answers

How to update HTML DOM with immer after State changes?

I do not completely understand how to use Immer state management, but I want to update my HTML after state changes with vanilla JS. So in this example, I need to rerender the HTML after baseState object changes. Is this possible with Immer? Or…
SERG
  • 3,907
  • 8
  • 44
  • 89
0
votes
1 answer

immer applyPatches not updating state

I'm trying to use immer patches to implement undo/redo functionality in my app. But for some reason, it doesn't work. I'm pasting the relevant snippet below. I confirmed that the "state" i pass to applyPatches has the new state/data, and that…
user3723491
  • 165
  • 4
  • 12
0
votes
1 answer

How does immer handle object keys with maps and sets?

The immer docs state "The keys of a map are never drafted! This is done to avoid confusing semantics and keep keys always referentially equal", but I'm having a tough time understanding what is meant by this. I expected this to mean that using a…
Matt Tingen
  • 118
  • 7
0
votes
1 answer

Component does not re-render when State is updated using react, redux and immer

I have a simple code which containing a PostFeed component to show feeds and PostItem component inside it which shows each feed. in PostItem user can do like feed and here a service call and a number of likes will change. if the current user has…
navid
  • 333
  • 4
  • 15
0
votes
1 answer

how is ImmerJS "strongly typed" if its plain javascript?

ImmerJS quotes itself as: Strongly typed, no string based paths selectors etc. https://immerjs.github.io/immer/docs/introduction#benefits If it's plain JS I wonder how it can be typed? What does 'strongly typed' mean in the context of JS? What is…
dcsan
  • 11,333
  • 15
  • 77
  • 118
0
votes
1 answer

Why is this state mutated by immer produce?

I'm receiving a state mutation error when using Immer's produce to manipulate the state. When I create a test interface manually inside the same reducer and call produce, it seems to work as expected: export interface ItemSliceState { items:…
0
votes
1 answer

Getting "Invariant Violation: Maximum update depth exceeded." error with ImmerJS

I have a React component which is a dynamic wizard implementing with Redux + ImmerJS. It renders a list of groups (forms) one at a time based on a JSON schema for users to fill in one at a time. Each group has a unique groupCode that can be used as…
Sean P.
  • 21
  • 4
0
votes
1 answer

How get updated state in produce of immer

Consider the following reducer: const initialBaseTestState = { oldValue: "String", something: "String two", }; const baseTest = produce((state = initialBaseTestState, action) => { const { type, data } = action; switch (type) { case SET_VALUE:…
M. Falex
  • 79
  • 2
  • 8
0
votes
1 answer

ReactJS - action to return a single item from reducer

The goal here is to call an action from my component and get the single object from the reducer, and with that object, I will load my form. Redux is working, but its returning the single object that I want as my whole state My component: const…
fjurr
  • 541
  • 2
  • 8
  • 23