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

154
Views
React native, state not defined in useSelector after fetch

I am trying to load data for my component in useEffect. How can I ensure the state is defined before I go to the next screen?

  const [rescueMeContent, setRescueMeContent] = useState({});

  useEffect(() => {
    async function fetchData() {
      const { payload } = await get('xxx');
      setRescueMeContent(payload);
    }
    fetchData();
  });

When I first run the app, on the next screen when I try and access the state like this I get an error saying its undefined:

  const {
    content: {
      splashScreen: {
        backgroundImage: { url },
        buttonText,
        informationText,
        title: pageTitle,
      },
    },
  } = useSelector((state) => state);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

useState works in inside only component. You can't reach that from other component. You must use react redux for to use useSelector. You must assign your fetch data to redux state with action. Then you can get that data with useSelector.

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!