【问题标题】:How does <Component {...pageProps} /> function?<Component {...pageProps} /> 是如何工作的?
【发布时间】:2019-11-07 03:44:32
【问题描述】:

这里是新手,

我从this 学习的代码和 我还发现几乎每个 _app.js 也有这行代码。

class Name extends App {
 render() {
    const { Component, pageProps } = this.props;
    const config = { some config here };
    return (
        <AppProvider config = { config }>
          <Component {...pageProps} />
        </AppProvider>
    );
  }
}

我知道&lt;Component {...pageProps} /&gt; 部分代表所有其他页面。当我浏览页面时,它会在 pageprops 中发生变化。

只是我不知道它如何调用其他页面?

【问题讨论】:

    标签: reactjs state shopify next.js react-component


    【解决方案1】:

    Component 是作为来自任何调用 Name 的组件的 prop 提供的(我们称之为 Foo)。

    正如你提到的导航改变道具,我假设当页面被导航时,这个Foo会发生一些变化,因此将不同的Component和/或pageProps传递给Name。因此,新页面中的Component 实例获得了新的道具。

    如果您想在其他页面中调用它,请检查它是如何从Foo 传递的,并在您的组件中遵循相同的方法。

    【讨论】:

      猜你喜欢
      • 2021-02-19
      • 2020-01-14
      • 1970-01-01
      • 1970-01-01
      • 2018-07-01
      • 2020-04-27
      • 2019-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多