Reputation: 2411
So currently I'm trying to render a DataTable
component. If I click on a button Users
, it should render a table of my Users
. When I click on the button Devices
, it should render a table of my Devices
. However, for some reason, it will only render the datatable of whichever one I click first.
E.g. if I click Devices
, it will render my Devices
table. Now, when I try to navigate to my Users
by clicking on the Users
button, it'll still display my Devices
datatable.
I maintain a state inside DataTable
and I'm updating the state with props that I pass into it. Is there a design flaw that I made that causes my DataTable
to not render the correct data?
Thanks for your help!
EDIT: Upon some debugging, it seems the state isn't being updated when I click on the Users
button
Upvotes: 0
Views: 2088
Reputation: 2411
Reading this React: Why component's constructor is called only once? solved my problem.
TLDR: Rendering the same component will not refresh the component. To overcome this, I needed to introduce a key
prop.
Upvotes: 1