功能?,reactjs,state,shopify,next.js,react-component"/>

首页 > 解决方案 > 如何功能?

问题描述

这里的新手,

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

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

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

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

标签: reactjsstateshopifynext.jsreact-component

解决方案


Component作为来自任何组件调用的道具提供Name(让我们调用它Foo)。

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

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


推荐阅读