W
W
WessBorland2020-02-17 16:05:12
React
WessBorland, 2020-02-17 16:05:12

Why does the Redux store change?

Hello.
I observe very strange behavior in the functional component
Stack React / Redux

Such a situation.

In a functional component, through props, I get an array from the redux store

Let 's say

const GroupUsersList = (props) => {
  const modules = props.data 

  if (чего то там) {
    modules.users.push({ _id: user._id, name: `${user.ФИО} (${user.login})` })
  }
  return (
    <>
    </>
  )
}
export default GroupUsersList;


But after I change the array using one of the array methods (push, splice
, etc.), I immediately change the data in the redux store.

What could be the reason for this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2020-02-17
@WessBorland

With the fact that objects (and arrays) in js are passed by reference. You are pushing into an array in the store. Obviously the array is changing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question