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

221
Views
state is undefined in useSelector in react native redux

I have been trying to learn redux for days but I can't learn it. state is undefined in useSelector in react native redux but this always happens when ever I use UseSelector the state is undefined please help. This is my my code in simplest form.

import React from 'react';
import {Provider} from 'react-redux';
import Home from './screens/home';

const App = () => {
  return (
    <Provider store={Store}>
      <Home />
    </Provider>
  );
};

//store
import {createStore} from 'redux';
export const Store = createStore(reducer);

//reducer
const initialState = {
  name: 'John',
};
function reducer(state = initialState, action) {
  return state;
}

//action
export const setName = () => {
  return {
    type: SET_USER_NAME,
  };
};

export default App;
import {StyleSheet, Text, View} from 'react-native';
import {useSelector} from 'react-redux';

const Home = () => {
  const state = useSelector(state => state);
  alert(state);
  return (
    <View style={styles.container}>
      <Text>Hello</Text>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});

export default Home;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are using store before it is initialised. Move

const App = () => {
  return (
    <Provider store={Store}>
      <Home />
    </Provider>
  );
};

in the bottom before export default App; then it works

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!