我收到这个错误:
TypeError: Cannot destructure property 'store' of 'useReduxContext(...)' as it is null.
尝试初始化slice.ts
像这样:
interface StateType {
authnRes?: AuthnRes
selectedOrganizationId?: string
selectedEventId?: string
soldTicketRes?: SoldTicketRes
isRegistrationInProgress?: Boolean
}
const initialState: StateType = {}
const tikexAPI = createSlice({
name: 'tikexAPI',
initialState,
并导出选择器slice.ts
像这样:
export const authnResS = (state: RootState) => state.tikexAPI.authnRes
export const userDTOS = createSelector(
[authnResS],
(authnRes?: AuthnRes) => authnRes?.data
)
并将其放入hooks.ts
:
export const useAppDispatch = () => useDispatch<AppDispatch>()
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
export const authnRes = (): AuthnRes | undefined => useAppSelector(authnResS)
export const userDTO = (): UserDTO | undefined => useAppSelector(userDTOS)
_app.tsx:
import { store } from '../tikexModule/store'
function MyApp({ Component, pageProps }: AppPropsWithLayout) {
const getLayout = Component.getLayout ?? ((page) => <Layout>{page}</Layout>)
return (
<Provider store={store}>{getLayout(<Component {...pageProps} />)}</Provider>
)
}
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)