Arrays in accessors chain get transformed into Objects
Closed this issue · 0 comments
kube commented
When accessor chain contains an Array, as in:
const state = {
title: 'Hello',
exercises: [
{ name: 'Bonjour' },
{ name: 'Hello' },
{ name: 'Hola' }
]
}
const newState = set(state, _ => _.exercises[0].name)('Salut')
Here newState.exercises
will be transformed in an Object:
const state = {
title: 'Hello',
exercises: {
'0': { name: 'Salut' },
'1': { name: 'Hello' },
'2': { name: 'Hola' }
}
}
This causes problem when using Array methods:
// Will throw an error as exercises does not have map method anymore
state.exercises.map(exercise => ... )