0

I have a stateless, functional component in NextJS where I'm trying to initialize some data upon load using getInitialProps():

const LoginModal = props => (
  <p>{props.testdata}</p>
);

LoginModal.getInitialProps = () => ({ testdata: 'Some string value' });

export default LoginModal;

However, no matter what I do, it always renders with a blank <p></p>. Why isn't the value returned by getInitialProps() being read by the component?

4

1 回答 1

3

它在这里工作,似乎您正在使用 getInitialProps 和 Pages 目录之外的组件,此功能仅在页面内可用,https://github.com/zeit/next.js/#fetching-data-and-component -生命周期

于 2017-08-09T09:03:05.340 回答