Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 反应:是什么控制这个.props.load的值?_Reactjs - Fatal编程技术网

Reactjs 反应:是什么控制这个.props.load的值?

Reactjs 反应:是什么控制这个.props.load的值?,reactjs,Reactjs,我有几个React容器和组件运行良好,但我仍在学习React。当我的功能componentDidMount在我正在处理的新组件中运行时,组件需要的所有数据似乎都可用于该组件,但this.props.loading设置为true componentDidMount() { const a = 100; //breakpoint here if (this.props.loading === false){ const {myDataID} = this.props;

我有几个React容器和组件运行良好,但我仍在学习React。当我的功能componentDidMount在我正在处理的新组件中运行时,组件需要的所有数据似乎都可用于该组件,但
this.props.loading
设置为
true

componentDidMount() {
    const a = 100; //breakpoint here
    if (this.props.loading === false){
        const {myDataID} = this.props;
        this.fromID = Meteor.userId();
        this.toID = myDataID;

        this.subscribe(fromID, toID);
    }
}

是什么控制
此.props.loading
中的值?如果
this.props.loading
设置为false,componentDidMount是否会再次运行?

prop
this.props.loading
由父组件设置。如果您觉得组件具有执行渲染所需的所有数据,则无需检查
此.props.load
是否为
true
false
。进行此检查是一种很好的做法,因为有时由于网络错误,您可能无法获得所需的数据。这将破坏您的代码

componentDidMount
仅在渲染函数完成后调用一次

在初始渲染发生之前,在客户端和服务器上调用一次。如果在此方法中调用setState,render()将看到更新的状态,并且尽管状态发生更改,但只执行一次

但是,当您更改父级中的
加载
道具时,
组件将使用
下一道具
调用
,这是您的更改

欲了解更多信息

是什么控制
此.props.loading
中的值

正在呈现该组件的组件。即,如果此
componentDidMount
方法位于组件
Bar
中,并且位于
Foo
渲染方法中:

render() {
   return <Bar loading={computeLoadingState()} />
}
render(){
返回
}
每次重新输入
Foo
时,
Bar
都有可能传递新值以加载

如果
this.props.loading
设置为false,
componentDidMount
会再次运行吗

不,报告说:

在初始呈现发生后立即在客户端(而不是服务器)上调用一次

但是,只要道具发生变化,就会调用