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
6
votes
0 answers

Using immer.js - reassigning draft array reference results in same array reference in state

I have this failing test using the produce method of immer.js: it('should replace array reference in state', () => { let state = { someArray: [1], }; const somArrayUpdate = [2, 3]; state =…
alex
  • 705
  • 9
  • 21
5
votes
0 answers

immer property change doesn't trigger update in functional component

I store a Node entity in state. When I click the button, I want to change the property 'title', and trigger component update to display the new title value. Nothing happens in the function component, it's only updated in class component. class…
Enivia
  • 192
  • 2
  • 11
5
votes
1 answer

Why immer.js doesn't allow setting dynamic properties on draft?

//I want my action to dispatch payload like // {type:'update',payload:{'current.contact.mobile':'XXXXXXXXX'}} //In reducer dynamically select the segment of state update needs to be applied to //Below code doesn't work as expected though,…
Viky293
  • 1,250
  • 12
  • 18
4
votes
0 answers

Produce a different type with immer in Typescript

Given a type type Data = Immutable<{ data: T }> const a: Data = { data: 0 } I'd like to use immer to transform this type into Data. produce(a, (d) => { d.data = d.data.toString() }) This obviously fails: Type 'string' is not…
Aleksandar Dimitrov
  • 9,275
  • 3
  • 41
  • 48
4
votes
3 answers

Immer error when using redux/toolkit with React-Native (iOS)

I'm trying to use @redux/toolkit in my react-native app. However, when I run the iOS simulator I get the following error. Metro has encountered an error: While trying to resolve module immer from file…
Ashish Dommety
  • 152
  • 2
  • 13
4
votes
1 answer

How to remove elements from array using redux, immer, react

import produce from "immer"; const initialState = { isLoading: true, error: "", burgers: [], }; export default function (state = initialState, action) { switch (action.type) { case "ADD_BURGER_BUCKET": { return produce(state,…
Rostyk
  • 939
  • 3
  • 13
  • 32
4
votes
0 answers

Update nested prop in immerjs causes "Cannot assign to read only property" exception

I'm trying to update a nested prop on one of my objects, which according to the docs should work exactly like that, I believe. Just the be clear the state has a list of lessons, each lesson has a list of modules and the module in question has a…
csim
  • 610
  • 7
  • 11
4
votes
0 answers

Type error when saving FormData when using Redux toolkit

I've tried to save FormData(Javascript's standard API) using redux toolkit. const initialState{ myFile: FormData | null } const controllerSlice = createSlice({ name: 'controller', initialState, reducers: { test: (state, action) => ({ …
JillAndMe
  • 3,989
  • 4
  • 30
  • 57
4
votes
1 answer

Using immer with IE11

I am using the latest version immer(6.0.5) - https://www.npmjs.com/package/immer and it does not seem to work with IE11 . Getting a cryptic error in the console Is there a work around to get produce from "immer" to work on IE11? SCRIPT1002: Syntax…
muddassir
  • 815
  • 9
  • 16
4
votes
5 answers

Typescript error when using immer for a Redux' reducer

I'm trying to use Immer with Redux in a Typescript project. Redux reducer could be typed as: Reducer I should be able to create an equivalent reducer with Immer's produce function which allows us to mutate a draft copy. But the…
Ben Carp
  • 24,214
  • 9
  • 60
  • 72
4
votes
2 answers

How to return initial state from a reducer using Immer?

I am working on a React project and using Redux for state management. I'm moving from ImmutableJS to Immer, and I'm not sure how to return the initial state with some changes. I was using merge from ImmutableJS, but not sure how to do it with…
4
votes
1 answer

How do you debug UI state using Immer?

I have a button that calls handleApplyFiltersButtonClick which updates the state by applying filters to some data. I have a bug somewhere. I'm struggling to debug the state which uses Immers' produce as everything is either a proxy or function. I…
Nick Lee
  • 842
  • 2
  • 11
  • 27
3
votes
2 answers

How to manage a selector that accepts arguments with yield select?

I have a React application where I'm using Redux and Redux-Saga and Reselect as selector library (with Immer to handle the immutability of the Redux state). I'm writing this question because I'd like to understand if my approach to handle the…
lucataglia
  • 728
  • 5
  • 18
3
votes
3 answers

Immer only supports setting array indices and the 'length' property

What types of things would cause Immer only supports setting array indices and the 'length' property' from the code below? This FoodLogState type is a class. I've done something very similar with no issue. I notice I am not updating even the array…
user275564
  • 163
  • 1
  • 2
  • 10
3
votes
2 answers

React js app - high severity vulnerability - immer

After installed react-router-dom. I saw that I had a vulnerability. exactly that: I didn't find much useful information for solve. Has anyone ever encountered this problem?
1
2
3
14 15