Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

115
Visualizações
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:

TypeError: Cannot read properties of undefined (reading 'value')

Code example below:

import React from 'react';
import { Text, View, Button } from 'react-native';
import Slider from '@react-native-community/slider';
import { TextInput } from 'react-native-paper';

class App extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        value1: 1
      };
    }

    render() {
        return(
            <View>
                <Text>Slider</Text>
                    <Slider 
                    value={this.state.value1}
                    onValueChange={(e) => this.setState({value1: e.target.value})}
                    minimumValue={1}
                    maximumValue={5}
                    step={1}/>
          </View>
      );
    }
  }
  
export default App;
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

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:

import React from 'react';
import { Text, View, Button } from 'react-native';
import Slider from '@react-native-community/slider';
import { TextInput } from 'react-native-paper';



    const App = (props) =>{
      const [value1 , setValue1] = React.useState(1)


        return(
            <View>
                <Text>The value is : {value1}</Text>
                    <Slider 
                    value={value1}
                    onValueChange={setValue1}
                    minimumValue={1}
                    maximumValue={5}
                    step={1}/>
          </View>
      );
    
  }
  
export default App;

demo

about 4 years ago · Juan Pablo Isaza Relatório

0

No mood property in your code. So it is undefined.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda