Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!