Questions tagged [immutability-helper]
23 questions
5
votes
1 answer
Using immutability-helper with Array, Object, Map
How do I do simple Create, Update/Modify, Replace, Delete using immutability-helper?
If I have an array of simple values?
If I have an array of simple objects?
If my array is in another object?
If I have an object of objects? (hashes, unordered)
If…

Finlay Beaton
- 601
- 6
- 15
5
votes
3 answers
Push new object at specific index using immutability helper
I have tried to do this:
const rowObj = {key: value};
const rowIndex = 2;
this.setState({
data: update(this.state.data,
{ [rowIndex] : { $push : [rowObj] } }
)
})
But, It throw error like this:…

Sagar Chavada
- 5,169
- 7
- 40
- 67
3
votes
1 answer
How to do conditional updates with Immutability-helper
I need to update some keys of a nested object, but whether or not each key is updated comes with some if condition.
Currently I am using lodash cloneDeep() like below ... which works fine, but I want to improve on performance so i want to use…

kernelman
- 992
- 1
- 13
- 28
3
votes
0 answers
immutability-helper: I can $set an item in a map but not $merge it, why? How can i $merge it?
Using typescript to modify an immutable state using the npm package 'immutability-helper' i'm facing some strange error (at least for now). I can set an object but not merge it. Can you clarify why?
Given the following data:
export enum NetworkState…

Mumrah81
- 2,034
- 2
- 16
- 23
2
votes
1 answer
Update a element inside object in aobject array with Immutability helper js
I need to add or subtract a value of a element in object array using Immutability helper
const selectedFood= [
{id: uuidv4(), name: "pizza", price: 1700, amount: 3},
{id: uuidv4(), name: "cheese", price: 600, amount: 10},
{id: uuidv4(), name:…

Yasas Lowe
- 91
- 1
- 6
2
votes
3 answers
Update nested object in array in ReactJs
I am having trouble updating a nested object in an array in react state.
I am trying to compare whether or not an item already exists in the state based off of the name of that item.
Here's what I am trying to have happen:
Add item to cart. If…

RogyBear
- 83
- 1
- 10
1
vote
1 answer
Using immutability-helper in React, update multiple values in one pass
Can you update two or more values in a nested state using one update method call from immutability-helper?
I tried the code below but only the last line [elementIndex]: {fouls: {$set: 1 }} gets implemented.
this.state={
players:[{points: 0,…

Andreas C
- 163
- 1
- 12
1
vote
1 answer
How can I update arbitrarily/dynamically nested data with immutability helper?
To update nested data with immutability helper, you usually hard-code the path to the data you want to update, sometimes with variables for keys. What do you do if the number of keys/indexes (that is, the depth of nesting) is also variable? I'm…

Qaz
- 1,556
- 2
- 20
- 34
1
vote
0 answers
Why does immutability-helper need `nextObject = object` after checking `nextObject === object`?
The part of source code is:
getAllKeys(spec).forEach(function(key) {
if (hasOwnProperty.call(commands, key)) {
var objectWasNextObject = object === nextObject;
nextObject = commands[key](spec[key], nextObject, spec, object);
if…

Eason
- 33
- 5
0
votes
1 answer
React state not updating on second index
I have nested objects as described below and updating states.
`
interface BookState {
name: string
authors: AuthorState[]
}
interface AuthorState {
name: string
}
const [bookValues, setBookValues] = useState(bookStateInitial)
//…

Bishal Heuju
- 13
- 6
0
votes
0 answers
Add new text field upon selecting a value using immutability helper in reactjs
I have a list of options
const values = [
{ firstName: 'John',
id: 'text'
}.
{
userId: 123,
id: 'number'
}
];
The logic is that the user selects one of the values (firstName) and an input field will…

Rak1994
- 65
- 2
- 11
0
votes
1 answer
Immutability Helpers in React Redux
I am learning React-Redux, and Recently I found about Immutability Helpers in React, Just Want to Know if it is good Practice to use Immutability Helpers in React Redux Operations and if yes/no, then why, I appreciate any detailed explanation, Thank…

Milan jotva
- 95
- 1
- 7
0
votes
1 answer
Can't access to variable inside a function arguments call
case 'ADD_CHAT_MESSAGE':
const index = state.tasks.findIndex(elm => elm.userid === action.taskid)
const task = state.tasks
return update(
state, { tasks: { index: { $set: action.task } } })
I would like to use index inside update…

infodev
- 4,673
- 17
- 65
- 138
0
votes
1 answer
Updating the array object in React state
I have a state as,
this.state = {
tempData: [{
"data": [{"id": "a1", "seatNo": 0},{"id": "a2", "seatNo": 0}],
"rowName": "a",
},{
"data": [{"id": "b1", "seatNo": 0},{"id": "b2", "seatNo": 0}],
"rowName": "b",
…

Shrutika
- 1
- 4
0
votes
1 answer
ReactJS - Proper way for using immutability-helper in reducer
I have the following object which is my initial state in my reducer:
const INITIAL_STATE = {
campaign_dates: {
dt_start: '',
dt_end: '',
},
campaign_target: {
target_number: '',
gender: '',
age_level: {
age_start:…

fjurr
- 541
- 2
- 8
- 23