react-boilerplate / react-boilerplate-cra-template

:fire: Setup Create React App with React Boilerplate. Highly scalable & Best DX & Performance Focused & Best practices.
https://react-boilerplate.github.io/react-boilerplate-cra-template/
MIT License
1.87k stars 395 forks source link

Redux State returns `undefined` after running the command `yarn cleanAndSetup` #157

Closed haihuynhsts closed 2 years ago

haihuynhsts commented 2 years ago

Before opening a new issue, please take a moment to review our community guidelines to make the contribution process easy and effective for everyone involved.

Description

The state in Redux store returns undefined

Steps to reproduce

Steps to reproduce the behavior:

I created a react app by using the command

yarn create react-app --template cra-template-rb my-app

After the app is created, everything just works perfectly. But after I run the command yarn cleanAndSetup

I created a new slice using yarn generate slice

When I tried to use the slice in my home page, then the page doesn't work anymore

image

Here is what I found from the browser console:

image

Turns out, it's because the state value in the below picture is undefined

image

Expected behavior The state value shouldn't be undefined

Screenshots If applicable, add screenshots to help explain your problem.

Versions

bharath-hebbar commented 2 years ago

Redux states are not initialized may be. Before extracting states const home = useSelector(selectHome), initialize redux state like const {actions} = useHomeSlice()

example:


import { useHomeSlice } from './pages/HomePage/slice'

const { actions } = userHomeSlice()
const home = useSelector(selectHome)

console.log(home)
haihuynhsts commented 2 years ago

Oh, it works like a charm. Thank you, now I understand why the error happened.