将next-redux-wrapper与redux-toolkit和RTK查询集成



我做了很长时间的研究,我不能使next-redux-wrapper, redux-toolkit和RTK查询的成功集成。

我想在下一个组件中调用getServerSideProps来加载userData,问题是我实际上不能使某事成功

const ToDoComponent = dynamic(() => import("../components/ToDoComponent"), {
loading: () => <NextNProgress />,
})
const ToDo = () => {
const username = useSelector((state) => state.useReducer.username)
const { isMobileState } = useIsMobile()
//const { data: darkmode} = useGetUserDarkModeQuery(username) /* i want to make those two calls before showing the todoComponent */
//useGetUserListsQuery(username) /* this one tho */
//wanna make those tho queries on getServerSideProps func
setNextTheme(darkmode)
useRedirect()
return (
<>
<ToDoComponent isMobileState={isMobileState} darkmode={darkmode} />
</>
)
}

export async function getServerSideProps() {
store.dispatch(listsApi.endpoints.getUserLists.initiate("hardcoded username"))
//this doesnt work, store is not defined, i try using wrappedStore but the actuall func has an error
}

要访问getServerSideProps中的存储,必须像next-redux-wrapper文档中所示那样包装该函数:

export const getServerSideProps = wrapper.getServerSideProps(store => ({req, res, ...etc}) => {
store.dispatch(listsApi.endpoints.getUserLists.initiate("hardcoded username"))
await Promise.all(dispatch(listsApi.util.getRunningQueriesThunk()))
});

相关内容

  • 没有找到相关文章

最新更新