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