Error: Unable to modify the value of a protected property '0' in the object 'Array'

I am facing a challenging issue with implementing a Material UI slider in conjunction with Redux. Below is the code for the slider component:

import { Slider } from '@material-ui/core'

const RangeSlider = ({handleRange, range}) => {
    
    const handleChange = (event, newValues) => {
        handleRange(newValues)
    }

    return (
        <Slider
            value={range}
            onChange={handleChange}
            valueLabelDisplay="auto"
            aria-labelledby="range-slider"
            min={0}
            max={100}
        />
    )
}

export default RangeSlider

Further down below is the filter component containing Redux logic:

import {
  Button,
  Typography as Tp,
  Select,
  MenuItem,
} from "@material-ui/core";
import { ExpandMore } from "@material-ui/icons";
import { RangeSlider } from "../components";
import { useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { filterUpdate } from "../redux/actions/filter";

const Filter = ({ models }) => {
  // Logic here...
};

export default Filter;

The Redux action logic is defined as follows:

import { createAction } from '@reduxjs/toolkit'
import types from '../types'

export const filterUpdate = createAction(types.FILTER_UPDATE)

Finally, here is the Reducer implementation:

import { createReducer } from '@reduxjs/toolkit'
import { filterUpdate } from '../actions/filter'

const reducer = createReducer({
    range: [0,60],
    model: 'None'
}, {
    [filterUpdate]: (state, action) => {
        state.range =  action.payload.range
        state.model = action.payload.modelSelected
    }
})

export default reducer

I encountered an error when integrating the Redux logic into my application. This error seems to be occurring randomly and inconsistently. How can I troubleshoot this issue? Any advice would be greatly appreciated.

Thank you in advance.

Answer №1

When working with the Slider component, I encountered an issue with sorting functions inside it. This was due to the fact that the value I passed into the component was immutable or read-only. To prevent this error from occurring, I needed to pass a copy of the range array as the value prop like so:

<Slider
    value={[...range]}
    // ....other props
/>

Answer №2

I am uncertain about the issue at hand, but it seems that there is a problem with your reducer implementation. Currently, you have:

const reducer = createReducer({
    range: [0,60],
    model: 'None'
}, {
    [filterUpdate]: (state, action) => {
        state.range =  action.payload.range
        state.model = action.payload.modelSelected
    }
})

A more appropriate approach might be:

const reducer = createReducer({
    range: [0,60],
    model: 'None'
}, {
    [filterUpdate]: (state, action) => ({
        range: action.payload.range,
        model: action.payload.modelSelected,
    })
})

In addition, it seems that you are not accessing the state from the Redux store properly. It appears that while you have imported useSelector, you are not utilizing it in your code. The outputs of useState and useDispatch are not related to each other within your current setup.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps do I need to take in order to display my data in a dynatree

Currently, I am in the process of developing a web application and incorporating dynatree for structuring purposes. EXAMPLE: Node 1 + Node 1.1 + Node 1.1.1 + Node 1.1.2 + Node 1.1.3 My goal is to introduce a child node (+Node 1.1.3.1) within th ...

Retrieve data from a variable that is located within a function that is also

<script> const tally ={ total: 0, increase: function(){ total++; console.log(total); } } const selectBtn = document.getElementsByTagName('button& ...

Using Python within HTML with Python integration

df2 = pd.DataFrame(np.random.randn(5, 10)).to_html() myPage = """ <html> <body> <h2> Programming Challenge </h2> <form action="/execute" method="get"> <sele ...

Dealing with performance issues in VueJS and Vuetify's data-table component, especially when trying to implement

In my VueJS and Vuetify project, I encountered an issue. I am trying to create a table with expandable rows for displaying orders and their associated products. The table needs to show at least 100 rows of orders on one page. To achieve this, I utilized th ...

Learn the art of blurring elements upon clicking in Vue

I've been attempting to trigger the blur event on an element when it is clicked, but I haven't been able to locate any helpful examples online. My initial approach looked like this: <a @click="this.blur">Click Me</a> Unfortunately, ...

Building a TypeScript Rest API with efficient routing, controllers, and classes for seamless management

I have been working on transitioning a Node project to TypeScript using Express and CoreModel. In my original setup, the structure looked like this: to manage users accountRouter <- accountController <- User (Class) <- CoreModel (parent Class o ...

How to extract a specific part of a string with regular expressions

I am currently working on a function to search for a specific substring within a given string. // the format is <stringIndex>~<value>|<stringIndex>~<value>|<stringIndex>~<value> var test = "1~abc1|2~def2|1~ghi3|4~jk-l4 ...

Error: The property 'count' cannot be destructured from '(0, react_redux__WEBPACK_IMPORTED_MODULE_3__.useSelector)(...)' because it is not defined

After watching this helpful tutorial: https://www.youtube.com/watch?v=iBUJVy8phqw I attempted to incorporate Redux into my Next.js app, following the steps outlined. However, I encountered a roadblock and can't figure out why. I've double-checke ...

Encountering a 404 error when trying to log in with Next-auth in the development environment

Encountering a 404 error after attempting to log in with Next-auth in a development environment. I am using version next-13.4.9 and next-auth-4.22.1, I have tried several solutions without success. Uncertain of the underlying issue. ...

What information is transferred when the submit button on a form is clicked?

Currently, I am utilizing node.js along with the jade templating engine. Within my jade file, I have a form structured like this: form.form-signin(style="padding-left:10px", action='/update', method='post') table.table.table-hove ...

Implementing Bootstrap in Angular 2 using vanilla JavaScript/ES6: A step-by-step guide

Currently, I am in the process of developing an Angular 2 application without TypeScript and facing difficulties with bootstrapping it as I cannot find any relevant examples. My app, which does not include the bootstrap() function, starts off like this: ...

The ion-input border seems to be fluctuating as the keyboard appears on the screen

I'm currently working with Ionic 3 and experiencing an issue where the selected ion-input's border in the ion-content is shifting when the device keyboard appears on the screen. Here is a visual representation of the problem: https://i.stack.imgu ...

What is causing onbeforeunload to consistently display a dialog box?

I'm facing an issue where my javascript code displays a confirmation dialog even when there is no unsaved data. I have simplified the problem to this bare minimum: window.addEventListener("beforeunload", (e) => { e.returnValue = null; retu ...

In search of assistance with a persistent react.js error plaguing my work

I keep encountering an error whenever I run npm start on a new project. Does anyone have any insight on how to resolve this issue? The problem might lie within the project dependency tree rather than being a bug in Create React App. Here is what you can ...

In jQuery, there seems to be an issue where the click event is not functioning properly on an element that has been

I am using jQuery to append items, but I am having trouble binding events to the appended items. My appending code looks like this: var item = '<div id="'+newInputId+'" class="col-md-9" style="padding-right: 0px; ...

Encountering a Type Error with Webpack4 when running npm start

When I run `npm start` on my Vue project, everything seems okay, but when I open the browser page, it shows up blank and gives me an Uncaught error: TypeError: Cannot read property 'call' of undefined The console view displays the following e ...

I am having trouble setting breakpoints in Google Chrome

For a while, I've been using Google Chrome to debug my JavaScript code without any issues. However, out of nowhere, I am no longer able to place breakpoints. When I click on the line number where I used to add breakpoints, nothing happens. Sometimes, ...

Component with Next.JS Server-Side Rendering

Is it possible to integrate a module into my project that only supports server side rendering? Here is the current project structure: index.js view.js part.js (Class component) Currently, I am able to use the module in the getServerSideProps method in ...

updating the HTML DOM elements using JavaScript is not yielding any response

One way that I am trying to change the background of a div is by using a function. Below is an example of the html code I am working with: $scope.Background = 'img/seg5en.png'; document.getElementById("Bstyle").style.background = "url("+$scope.B ...

How can I resolve the "AngularJS 1.6.6 component controller not registered" error plaguing my application?

I am currently using AngularJS version 1.6.6 along with Gulp for my project. Here are the snippets of my code, particularly focusing on the AppLayout component: /// app-layout.component.js angular.module('app').component('appLayout&ap ...