I got the following error when I was using redux:
TypeError: react__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function
How do I solve this? I have added the code below.
dispatch()
is being called in the component below
import authAction from "../store/Auth";
import { useDispatch } from "react-redux";
const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
},
menuButton: {
marginRight: theme.spacing(2),
},
title: {
flexGrow: 1,
},
}));
export default function Header() {
const classes = useStyles();
const dispatch = useDispatch();
console.log("Auth:", authAction);
return (
<div className={classes.root}>
<AppBar position="static">
<Toolbar>
<Typography variant="h6" className={classes.title}>
Counter
</Typography>
<Button
color="inherit"
onClick={() => {
dispatch(authAction.login());
}}
>
Login
</Button>
</Toolbar>
</AppBar>
</div>
);
}
creatSlice
component:
import { createSlice } from "@reduxjs/toolkit";
const authSlice = createSlice({
name: "Auth",
initialState: { loggedIn: false },
reducers: {
login(state) {
state.loggedIn = true;
},
},
});
export const authActions = authSlice.actions;
export default authSlice.reducer;
configureStore
component:
import { configureStore } from "@reduxjs/toolkit";
import auth from "./Auth";
const store = configureStore({
reducer: {
auth: auth,
},
});
export default store;
Thank you.