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

310
Visualizações
React Native simple useState does not work, state is staying 'undefined' and "setState is not a function"

I have just a simple React-Native Component that uses useState as a test if it works. When I set the userstate, and I just print it, it logs 'undefined'. Also when I call setUser, it throws an error, that setUser is not a function. Whats wrong with my Setup?:

import { StyleSheet, Text, View, TextInput, Button, Seperator, Pressable } from 'react-native'
import React, {useState, useEffect} from 'react'
import colors from '../theme/colors.style.js'
import NetInfo from '@react-native-community/netinfo';
import { checkConnected } from '../utils/Netinfo.js';

export default function  MachineManager() {
  const {connectStatus, setConnectStatus} = useState(false);
  const {user, setUser} = useState("martin");
  console.log(user);

  return (
    <View style={styles.container}>
      <View style={styles.connectorMenu}>
        <View style={styles.shadowView}>
          <View style= {styles.connectionMenuHeader}>
            <Text style={styles.connectionMenuHeaderText}>Verbundenes Gerät</Text>
          </View>
          <View style={styles.inputRow}>
            <Text style={styles.inputLabel}>SSID:</Text>
            <TextInput placeholder="SSID Kennung" style={styles.input}/>
          </View>
          <View style={styles.inputRow}>
            <Text style={styles.inputLabel}>Passwort:</Text>
            <TextInput placeholder="Passwort" style={styles.input}/>
          </View>
          <View style={styles.connectionControl}>
            <View style={styles.connectionControlStatus}>
              <Text style={styles.connectionControlStatusText}>Status: Nicht Verbunden</Text>
              <Text style={styles.connectionControlStatusText}>{user}</Text>
            </View>
            <View style={styles.connectionControlConnect}>
              <Pressable style={styles.connectButton}>
                <Text style={styles.connectButtonText}>Verbinden</Text>
              </Pressable>
            </View>
          </View>
        </View>
      </View>
    </View>
  )
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The syntax is incorrect. It needs to be -

const [connectStatus, setConnectStatus] = useState(false);
const [user, setUser] = useState("martin")
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