我有个问题。使用 getInitialProps 函数,返回值没有转到父组件。
但是,在 getInitialProps 函数中,我在 console.log 中看到了正确的值
实体代码下方
import * as React from "react";
import {dynamicPost} from "../../store/dynamicPost";
import AppLayout from "../../components/AppLayout";
import {toJS} from 'mobx';
import {useRouter} from 'next/router'
const Post = ({post}) => {
console.log("in Post, props ", post); // <<<<<<<<<<< undefined. why?????
const router = useRouter();
const {id} = router.query;
return (
<AppLayout>
<div>{id} article</div>
</AppLayout>
);
};
Post.getInitialProps = async ({res, query}) => {
console.log("in Post, getIP, res ;", res);
console.log("in Post, getIP, query ;", query); // { id : 3 }
await dynamicPost.eReactPostR(query.id);
let post = await toJS(dynamicPost.eRPrender)
console.log('in getinitialProps data;' , post); // here, the value was that I want it
return post;
};
export default Post;
四季花海
相关分类