Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
Array.Map() is changing state without using return value

I am coding along with the Redux Essentials tutorial.

When I run notificationArray.map without using the return value, my state is updated per the map functions callbacks.

I.e. in allNotifiicationsRead, each notifications's read property is set to true in the app state. And in fetchNotifications, all each notification's isNew property is set to !read.

I would expect this notificationArray.map(...) call to not have any effect since, I am not using the return value, let alone editing the state with it such as something like notificationsAdapter.setMany(notificationArray).

Any clarification on how this is working would be appreciated.

Please let me know if I didn't include any relevant details about this app.

const notificationsSlice = createSlice({
    name: 'notifications',
    initialState: notificationsAdapter.getInitialState(),
    reducers: {
        allNotificationsRead(state, action) {
            const notificationArray = Object.values(state.entities)
            notificationArray.map(notification => (
                notification.read = true
            ))
        }
    },
    extraReducers(builder){
        builder.addCase(fetchNotifications.fulfilled, (state, action) => {
            notificationsAdapter.upsertMany(state, action.payload)
            const notificationArray = Object.values(state.entities)
            notificationArray.map(notification => (
                notification.isNew = !notification.read
            ))
        })
    }
})
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda