【发布时间】:2020-02-07 11:28:47
【问题描述】:
我主要有 3 个组件- 联系组件 - 它将加载,因为 fetch api 是在 ComponentDidMount 中编写的,我们可以看到数据 - 它显示了用户列表
当您单击特定用户时,它具有 id 作为参数,并将在 handleClick 中调用另一个 api,并成功获得响应并更新状态。理想情况下,当 state 更新时,contact Component render 需要再次渲染,并且我们有 state 中的数据,它会显示子组件,但它没有显示。
我的理解是,每当状态发生变化时组件都会重新渲染,那时我的条件得到满足并会显示子组件。 如有错误请指正
这里是带有代码的编辑器的链接
https://codesandbox.io/s/pensive-microservice-4jem7?fontsize=14
```Step1-Click on Contact link```
```Step2-ComponentDidMount works and will load content```
```Step3-try to click any edit button of any user-HandleClick will work and will fecth data and update state,but its not showing the child component,thats is supposed to render when data is there```
【问题讨论】:
-
请添加您尝试过的代码。以及您拥有的组件。
-
@its4zahoor 你能检查一下这个链接吗 -codesandbox.io/s/pensive-microservice-4jem7?fontsize=14 它的所有组件都在 src 文件夹中
-
我看到了,它工作正常,您将数据对象与 fetchUser 对象混淆了。
-
确定..我在聊天室@its4zahoor
标签: reactjs