admin管理员组文章数量:1401955
I am using NextJS App Router (NextJs13+),
currently I am fetching data on the server components then passing it as a prop to client component.
Client component has a useEffect and does dispatch to update the redux store.
I feel like this is wrong? is there a way to update redux before the client component renders?
I am basically doing the following:
// Server component
const ProfilePage: React.FC = async () => {
const userDTO = await getUser();
const userState = convertDTOToEditUserPageState(userDTO);
return <PageContent user={userState} />;
};
export default ProfilePage;
// Client component
const PageContent: React.FC<PageContentProps> = ({user}) => {
const dispatch = useDispatch();
useEffect(() => {
dispatch(updateEditUserState(user));
}, [user]);
const userFromStore: EditUserPageState = useSelector(currentUserSelector);
本文标签: reactjsHow can I update redux store from server componentStack Overflow
版权声明:本文标题:reactjs - How can I update redux store from server component? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744313352a2600138.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论