简体   繁体   English

Reactjs-为什么我的MaterialUI数据表没有刷新?

[英]Reactjs - Why doesn't my MaterialUI Datatable refresh?

So currently I'm trying to render a DataTable component. 所以目前我正在尝试呈现一个DataTable组件。 If I click on a button Users , it should render a table of my Users . 如果我单击“ Users按钮,它应该呈现“ Users表。 When I click on the button Devices , it should render a table of my Devices . 当我单击Devices按钮时,它应该呈现我的Devices表。 However, for some reason, it will only render the datatable of whichever one I click first. 但是,由于某种原因,它只会呈现我首先单击的那个数据表。

Eg if I click Devices , it will render my Devices table. 例如,如果我单击Devices ,它将呈现我的Devices表。 Now, when I try to navigate to my Users by clicking on the Users button, it'll still display my Devices datatable. 现在,当我尝试导航到我的Users通过点击Users按钮,它仍然显示我的Devices数据表。

I maintain a state inside DataTable and I'm updating the state with props that I pass into it. 我在DataTable维护一个状态,并使用传递给它的道具更新该状态。 Is there a design flaw that I made that causes my DataTable to not render the correct data? 我是否存在设计缺陷,导致我的DataTable无法呈现正确的数据?

Thanks for your help! 谢谢你的帮助!

EDIT: Upon some debugging, it seems the state isn't being updated when I click on the Users button 编辑:经过一些调试,当我单击“ Users按钮时,似乎状态没有更新

Reading this React: Why component's constructor is called only once? 阅读此React:为什么组件的构造函数仅被调用一次? solved my problem. 解决了我的问题。

TLDR: Rendering the same component will not refresh the component. TLDR:呈现相同的组件不会刷新该组件。 To overcome this, I needed to introduce a key prop. 为了克服这个问题,我需要介绍一个key道具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM