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

223
Views
Error Type: undefined is not an object (evaluating '_useSelector.attendance')

I'm having a challenge with redux as I keep getting this error: TypeError: undefined is not an object (evaluating '_useSelector.attendance'). Everything seems to be working fine but I just done understand why it keeps coming back to this even when it seems the code is okay to my knowledge

Reducers.js

import { GET_ATTENDANCE, ADD_TO_ATTENDANCE_LIST } from "./actions";


const initialState = () => ({
  attendance: [],
  attendancebook: [],
});

function attendanceReducer(state = initialState, action) {
  switch (action.type) {
    case GET_ATTENDANCE:
      return { ...state, attendance: action.payload };
    case ADD_TO_ATTENDANCE_LIST:
      return {
        ...state,
        attendancebook: [...state.attendancebook, action.payload],
      };
    default:
      return state;
  }
}

export default attendanceReducer;

AttendanceScreen.js

function AttendanceScreen({ route }) {
  const navigation = useNavigation();
  const listing = route.params;
  const dispatch = useDispatch();

  const { attendance, attendancebook } = useSelector(
    (state) => state.attendanceReducer
  );

  const getAttendance = () => {
    try {
      dispatch({
        type: GET_ATTENDANCE,
        payload: attendancelist,
      });
    } catch (error) {
      console.log(error);
    }
  };

  const fetchAttendance = () => dispatch(getAttendance());

  const addToAttendanceList = (data) => dispatch(addAttendance(data));

  useEffect(() => {
    fetchAttendance();
  }, []);

store.js

import attendanceReducer from "./reducers";

const persistConfig = {
  key: "root",
  storage: AsyncStorage,
  whitelist: ["attendancebook"],
};

const rootReducer = combineReducers({
  attendanceReducer: persistReducer(persistConfig, attendanceReducer),
});

export const store = createStore(rootReducer, applyMiddleware(thunk));
export const persistor = persistStore(store);

actions.js

export const GET_ATTENDANCE = "GET_ATTENDANCE";
export const ADD_TO_ATTENDANCE_LIST = "ADD_TO_ATTENDANCE_LIST";

export const addAttendance = (data) => (dispatch) => {
  dispatch({
    type: ADD_TO_ATTENDANCE_LIST,
    payload: data,
  });
};

Please any help will be appreciated.

about 4 years ago · Juan Pablo Isaza
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!