I am trying to learn redux code by implementing the below tutorial
I am not able to see the console log for habits in the browser
providing my code snippet below
can you let me know how to fix it
https://www.youtube.com/watch?v=-ovliZG617g&t=1310s
https://codesandbox.io/p/sandbox/yxtwjg?file=%2Fsrc%2Fcomponents%2Fhabits-list.tsx%3A9%2C6
import React from "react";
import { useSelector } from "react-redux";
import { RootState } from "../store/store";
import { Box } from "@mui/material";
const HabitList: React.FC = () => {
const { habits } = useSelector((state: RootState) => {
state.habits;
});
return <Box>{console.log("habits", habits)}</Box>;
};
export default HabitList;
2
Answers
This is because you haven’t included the HabbitList component in the App.
Make the following changes to your app.tsx;
First import the component.
And then include that component in the
<App>
just below the<AddHabitForm />
Insert the HabitList into the App computer.
Also, currently, the function inside the useSelector doesn’t return anything. You should remove those parentheses.
Here’s the updated the code
habits-list.tsx
App.tsx