小编AO *_*lts的帖子

getInitialProps永远不会被调用...我在做什么错?

我是React和Next.js的新手,所以请多多包涵。但是我花了三个小时进行搜索,因此无法终生弄清自己在做什么错。

this.props.test 即使看起来应该输出“ test”,也不会输出任何东西。

就像getInitialProps从来没有调用过。

class Example extends React.Component {

  static async getInitialProps() {
    return {
      test: 'test'
    }
  }

  render() {
    return (
      <h1>Hi {this.props.test}</h1>
    )
 } 

}
Run Code Online (Sandbox Code Playgroud)

reactjs next.js

3
推荐指数
2
解决办法
2930
查看次数

标签 统计

next.js ×1

reactjs ×1