-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
`
import { createSlice } from "@reduxjs/toolkit";
import type { PayloadAction } from "@reduxjs/toolkit";
import { useAppSelector } from "../store";
// Define a type for the slice state
interface UiState {
popups: [];
}
// Define the initial state using that type
const initialState: UiState = {
popups: [],
};
export const uiSlice = createSlice({
name: "ui",
initialState,
reducers: {
openPopup(state, action) {
const { id, element } = action.payload;
state.popups.push({ id, element });
},
},
selectors: {
selectUI: (ui) => ui,
},
});
export const useUI = () => useAppSelector((state) => uiSlice.selectSlice(state)); // WORK FINE
// export const useUI = () => useAppSelector(uiSlice.selectSlice); // NOT WORKS
/** ERROR IN CONSOLE
- @reduxjs_toolkit.js?v=791f25be:2571 Uncaught TypeError: Cannot read properties of undefined (reading 'reducerPath')
at selectSlice (@reduxjs_toolkit.js?v=791f25be:2571:37)
at selectSlice (react-redux.js?v=791f25be:189:28)
at memoizedSelector (react-redux.js?v=791f25be:46:38)
at getSnapshotWithSelector (react-redux.js?v=791f25be:74:22)
at mountSyncExternalStore (chunk-ZRJG7NCB.js?v=791f25be:12509:28)
at Object.useSyncExternalStore (chunk-ZRJG7NCB.js?v=791f25be:13196:22)
at useSyncExternalStore (chunk-2EXEP7CN.js?v=791f25be:1120:29)
at useSyncExternalStoreWithSelector3 (react-redux.js?v=791f25be:81:23)
at useSelector2 (react-redux.js?v=791f25be:243:27)
at useUI (slice.ts:30:28)
*/
`
Metadata
Metadata
Assignees
Labels
No labels