[问题] React初始化资料的写法疑问

楼主: aoksc (重出江湖)   2017-08-01 22:44:26
请问各位
我用React来写一个典型的查询页面
主要分成两块
分别是search board也是parent component
在这里输入资料并用ajax查询
查询完的结果送到result panel也就是child component
如果是第一次加载页面
我默认查询是写在componentDidMount()
并用this.setState设定
但我发现我这样做他并不会传给child component
即便我有设定state并把值pass给result panel
但result panel接到的资料笔数却是0笔(我是传array)
请问像这种情况
我如果任何资料都是从parent component传给child component
包含连初始化的资料也是
那请问初始化的资料要写在哪里才会正确的传给child component
并且正确的render?
还有我用chrome dev tool看
我发现好像是从child component开始render
再换parent component render
请问是因为这样的关系
所以即便我在parent component的componentDidMount()设定完资料
因为child component已经初始化完所以不会重新render?
请问这个现象有什么文章可以学习呢?
谢谢
作者: chatnoir (对不起)   2017-08-01 23:07:00
你是用props传到child吗?
楼主: aoksc (重出江湖)   2017-08-02 08:41:00
我是用state传值
作者: illl (ill!)   2017-08-02 09:51:00
code贴上来阿
作者: spjay1 (Josh)   2017-08-02 22:54:00
child 有没有 willreceiveprops ?
作者: chatnoir (对不起)   2017-08-02 23:39:00
state是元件自己的状态,元件与元件沟通要用props

Links booklink

Contact Us: admin [ a t ] ucptt.com