Immutability with Redux and useSelector

Immutability with Redux and useSelector

Recently, after having a look at a pull request, I’ve seen a colleague using the keyword delete directly on an object coming out from a useSelector.

Recently, after having a look at a pull request, I’ve seen a colleague using the keyword delete directly on an object coming out from a useSelector.

Even if applying delete on JS object is not really a good practice and very often subject to side effects, we were wondering how bad the redux store would be affected by the delete.

Spoiler alert: It’s VERY bad

Demonstration

I’ve created a new project on sandbox.io to do my tests. The two main files which will be interesting for us are the main file (App.js) and the User Reducer (userReducer.js) which also contains the actions for the purpose of this article.

Image for post

App.js

Image for post

userReducer.js

redux react-redux react

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

React Native Redux | How To Use Redux In React Native

React Native Redux Example Tutorial From Scratch. We connect the React Native app to Redux store to save and retrieve the application data.

React and React Redux — Connecting to Redux

Redux is a light weighted State Management Tool that helps the components in our React App to communicate with each other. The simple concept behind this is that every state of the component is kept in a store that will be global. So that every component can access any state from that store.

Accessing Redux from Components In React & React Native

How to set up a basic version of Redux in your React or React Native application. To make things clearer, I based my setup on my event application, where users create events that other users attend. We generated the action creators, reducers, and Redux store, and wrapped the application in a provider.

A Basic Redux Setup in React/React Native

Redux is a powerful state management tool that can be very useful as your React or React Native application grows and requires you to keep track of more state.