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

196
Views
React Native: why are useState hooks sometimes undefined?

In my React Native app I have two components, A and B:

export const A = () => {
  const [text, setText] = useState('');
  return (
    <View>
      <B
        _text={text}
        _setText={setText}
      />
    </View>
  )
}

const B = ({_text, _setText}) => {
  console log(_text, _setText);
  ...
  ...
}

I console.log _text and _setText in B. This console.log gets called multiple times whenever I open the B component, and sometimes it logs both _text and _setText as undefined.

Does anyone know why this would be?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're most likely rendering the B Component before the text state is updated. To fix it, check that it isn't null/empty:

export const A = () => {
  const [text, setText] = useState('');
  return (
    <View>
      {text ? <B
        _text={text}
        _setText={setText}
      /> : null}
    </View>
  )
}
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!