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

redux toolkit 1.5.1 does deep copy, but caling produce from 8.0.4 immer not working in react-native android

I tested out produce method from immer library AND tried to use import immer/es5 which did not import. Doing an import immer works fine, but the deep copy fails in that "the initial object is modified" for the following code const child = new…
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
0
votes
1 answer

How to organise my nested object for better state management?

This is more of an organisation than technical question. I think I may be adding complexity, where a more experienced dev would simplify. I lack that experience, and need help. It's a menu editor, where I load a menu object from my database into…
sashaikevich
  • 167
  • 13
0
votes
0 answers

correctly typing using immer to make a svelte store

import produce from 'immer'; import { writable } from 'svelte/store'; const initialValue = { toiletsCleaned: 0, }; const { subscribe, set, update } = writable(initialValue); export const barStore = { subscribe, cleanToilet: () => { …
James Wilson
  • 852
  • 13
  • 29
0
votes
1 answer

Selector returns empty array from the redux state, even though the array has values

I have the following normalized redux state: rootReducer: { blocks: { "key1": { id: "key1", beverages: [], // Array of objects } } } and I'm trying to select the value of beverages for beverage with the id of "key1" using…
mtbno
  • 561
  • 7
  • 12
0
votes
0 answers

How to re-enable warning/errors of React app in console?

I am using a typescript version of React and continue to coding. After 2 weeks I encounters with a bad functionality of React/webpack because these tools has been stopped showing me the warnings such as unused variable and so on. I didn't change…
Hamed Sanaei
  • 121
  • 13
0
votes
1 answer

Using immer can not modify property Number of nested object

I am using Angular 2+ with Redux and is fine, but can not modify quantity with the new value The error is: TypeError: Cannot assign to read only property 'quantity' of object '[object Object]' export interface CartState { readonly cars:…
0
votes
1 answer

Object still frozen when using Immer and NGXS

I am implementing ngxs into an existing codebase. I have imported Immer and then ngxs bridge in hopes to handle side effects easier. I've followed every example that I can find through google, I always get: core.js:6014 ERROR TypeError: Cannot…
grahamama
  • 23
  • 4
0
votes
2 answers

Functions in a jest test only work when launched alone, but not at the same time

I have a custom hook that updates a state. The state is made with immer thanks to useImmer(). I have written the tests with Jest & "testing-library" - which allows to test hooks -. All the functions work when launched alone. But when I launch them…
DoneDeal0
  • 5,273
  • 13
  • 55
  • 114
0
votes
1 answer

Where to write mutable and where immutable logic with @redux/toolkit?

I had the exact same problem as in this question here. With this code: set(state, action) { const { id, value, field } = action.payload const range = state.ranges.find(r => r.id === id) range[field] = new Date(value) //action.payload.field can…
Alex l.
  • 213
  • 1
  • 14
0
votes
1 answer

Generic parameter in conditional type produces unexpected variance

Given the following code, I expect it to compile without errors: type Immutable = T extends object ? { readonly [K in keyof T]: Immutable; } : T; function foo(t: T): Immutable { return t; } Open in playground However…
Veetaha
  • 833
  • 1
  • 8
  • 19
0
votes
1 answer

Why use immer for this function?

ToggleAttached function inside CauseSpecificPage.js. This function toggles the follow/following button on the cause specific page: st-bnv. What is the benefit of using Immer in this situation? Do we even need to use Immer? const ToggleAttached = ()…
0
votes
1 answer

C# generate TypeScript class with TypeGen and set [immerable] = true

We are using TypeGen to generate TypeScript classes from our C# classes. It works like this: [ExportTsClass] public class MyClass { public int MyProperty { get; set; } public string MyField { get; set; } public string MyProperty2 { get;…
Ogglas
  • 62,132
  • 37
  • 328
  • 418
0
votes
1 answer

Strange behviour of state in slice redux-toolkit (revoked proxy)

Sandbox: https://codesandbox.io/s/ucjrx?file=/src/features/todos/todosSlice.js In todoSlice.js, at line 14, when I try to do console.log, it is printed as a revoked proxy (browser console). But when I put a breakpoint in chrome dev tools and go…
0
votes
1 answer

Optimistic UI (react, swr, immer)

I would love a short code review of "my" implementation of optimistic ui patterns. I'm using SWR, immer and a custom fetch hook to do most of the heavy lifting. However, I'm not really sure if this is indeed the way to do it. Especially when it…
0
votes
1 answer

Typescript Object is possibly 'undefined' after check

Quick question - why Typescript still thinks it will be undefined? When added code below to my application I have Typescript Error on line draft.splice(result.destination.index, 0, draggedItem); saying that result.destination Object is possibly…
tommybernaciak
  • 390
  • 2
  • 17