Our ActionForm component is mutating the rule.actions state by pushing elements into it, instead of using React's callback to update the state. This is something we should avoid, as explained in the React Documentation:
In JavaScript, arrays are just another kind of object. [Like with objects](https://react.dev/learn/updating-objects-in-state), you should treat arrays in React state as read-only. This means that you shouldn’t reassign items inside an array like arr[0] = 'bird', and you also shouldn’t use methods that mutate the array, such as push() and pop().
Current scenario
Rule definition as a state, one of its props is actions. (source code link)
Issue
Our
ActionForm
component is mutating therule.actions
state by pushing elements into it, instead of using React's callback to update the state. This is something we should avoid, as explained in the React Documentation:In JavaScript, arrays are just another kind of object. [Like with objects](https://react.dev/learn/updating-objects-in-state), you should treat arrays in React state as read-only. This means that you shouldn’t reassign items inside an array like arr[0] = 'bird', and you also shouldn’t use methods that mutate the array, such as push() and pop().
Current scenario
Rule definition as a state, one of its props is
actions
. (source code link)rule.action
being passed by toActionForm
component (source code link)rule.action
being mutated inside theActionForm
component several times, for example (source code link)Expected outcome
We would refactor the code so it calls the dispatcher function instead of mutating the actions array