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

106
Visualizações
React Native (getting value from text input)

So I'm doing a little personal project and I'm having some trouble getting the numeric value from the textinput. I'm either getting an error saying the function expected a string or undefined.

Below is the source code:

//Timer state
  const [timer, setTimer] = useState({
    work: 0.3,
    break: 0.2,
    longBreak: 0.5,
    active: "work",
  });

  const workTime = timer.work;
  const breakTime = timer.break;
  const longBreakTime = timer.longBreak;

This is where the value is supposed to be passed :

function handleChange(name, value) {
    console.log(value);

    switch (name) {
      case "work":
        setTimer({ ...timer, work: parseInt(value) });
        break;
      case "break":
        setTimer({ ...timer, break: parseInt(value) });
        break;
      case "longBreak":
        setTimer({ ...timer, longBreak: parseInt(value) });
      default:
        break;
    }
  }

I'm trying to retrieve the value from this text input:

 <TextInput
              style={styles.input}
              onChange={(workTime) => handleChange("work", setTimer(workTime))}
              placeholder="Work"
              keyboardType="numeric"
              numeric
              value={workTime}
              name="work"
            />
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

onChange={(workTime) => handleChange("work", workTime)}

you are passing a call to the hook function instead of the value you read from the input

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