Skip to content
Advertisement

Cannot read properties of undefined (reading ‘value’)

this is very basic but I’m new to JS and new to React, I need a few pointers on what I’m doing wrong. I have a Slider components I would like to change, and I would like to reflect/store the new value of the Slider in the class state. How should I be writing this?

I get this error:

JavaScript

Code example below:

JavaScript

Advertisement

Answer

there is no mood property in your code, I highly recommend you to work with functional components instead of class components to be able to use hooks and make your code more clean and readable. for more information check React Functional Components VS Class Components

I revised your code, now it updates the state of value1 whenever the slider moves:

JavaScript

demo

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement