reactjs - 如何功能?
问题描述
这里的新手,
我从中学习的代码,我还发现几乎每个 _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 中发生变化。
只是我不知道它如何调用其他页面?
解决方案
Component
作为来自任何组件调用的道具提供Name
(让我们调用它Foo
)。
正如您提到的导航更改道具,我假设当页面被导航时,这Foo
会发生一些变化,因此会传递一个不同的Component
和/或pageProps
到Name
. 因此,Component
新页面中的实例获得了新的道具。
如果您想在其他页面中调用它,请检查它是如何传递的,Foo
并在您的组件中遵循相同的方法。
推荐阅读
- scala - 在 Spark Scala 中对数组的每个成员应用函数
- gitlab-ci - 如何在 Gitlab CI/CD 管道中集成 Veracode SAST 和 DAST 扫描
- javascript - Vue 3:我无法向下或向上滚动
- flutter - Flutter:如何将 FloatingActionButton 放置在持久性底页后面?
- python - 如何根据熊猫数据框中的现有列创建新列?
- php - 基于noscript的“隐藏页面源”(更改页面)
- javascript - MDBCarousel 的控制箭头出现在轮播上方而不是侧面
- php - 我们如何使用 PHP 读取 .doc 和 .doxc 文件?
- java - 当我尝试通过按钮从另一个类访问 GUI 时,只弹出一个标题栏
- css - 如何在另一个元素的焦点上使用 sass 更改背景图像