Seeing header but not rows
The code below gives me a table with a header row, but no rows below it with data. I've confirmed that the data variable is populated correctly. Can somebody tell me what I'm missing please?
26 Replies
generous-apricotā¢14mo ago
Are your colDefs and data memoized?
optimistic-goldOPā¢14mo ago
I don't believe so. Console.log is printing out correct values for data
generous-apricotā¢14mo ago
Try memoizing your data, and then if that does not do the trick then next the colDefs.
generous-apricotā¢14mo ago
Found the docs on it: https://tanstack.com/table/latest/docs/guide/data#give-data-a-stable-reference
Data Guide | TanStack Table Docs
Data Guide
Tables start with your data. Your column definitions and rows will depend on the shape of your data. TanStack Table has some TypeScript features that will help you create the rest of your table code with a great type-safe experience. If you set up your data and types correctly, TanStack Table will be able to infer the shape of your ...
optimistic-goldOPā¢14mo ago
Ah. I'm using useState for data, is that the same?
generous-apricotā¢14mo ago
Yea, that should work.
optimistic-goldOPā¢14mo ago
colDefs is defined outside the components, so both of them should be stable
generous-apricotā¢14mo ago
Can you throw this in a stackblitz repro? I could take a look at it.
Maybe using the json placeholder api for data or just a faked promise.
May only be able to check it tomorrow though (its 1am here in NZ š
)
optimistic-goldOPā¢14mo ago
https://react-vmr4gx.stackblitz.io
Not sure what to do to handle the imports
generous-apricotā¢14mo ago
Can you post the link where with the editor in it? this seems to be the preview link.
Edit: Share button basically
optimistic-goldOPā¢14mo ago
optimistic-goldOPā¢14mo ago
Ok, wait, looks like I need an account
Looks like it's working now
generous-apricotā¢14mo ago
šš¼
Cool stuff
optimistic-goldOPā¢14mo ago
I mean, stackblitz is working
My code is not š
generous-apricotā¢14mo ago
LMAO, ok ok ok.
Drop the working stackblitz link when ready.
optimistic-goldOPā¢14mo ago
That
generous-apricotā¢14mo ago
Your data is undefined

optimistic-goldOPā¢14mo ago
Ah I only put in the client code, 1 moment
generous-apricotā¢14mo ago
nvm, I can refactor this to use the json placeholder api
generous-apricotā¢14mo ago
Sean Cassiere
StackBlitz
React (forked) - StackBlitz
A create-react-app project based on react and react-dom.
generous-apricotā¢14mo ago
Its working. You should probably validate your server responses.
Also, I've adjusted the Table components api so it takes in a named prop as well as setting a default empty array state.
optimistic-goldOPā¢14mo ago
Wait.. so you're saying you didn't change anything? It's working with the placeholder api?
generous-apricotā¢14mo ago
No, I made those changes I mentioned.
Lemme put some comments marked with
IMPORTANT:
š¢ updated with the comments.
Just search for IMPORTANT:
optimistic-goldOPā¢14mo ago
Thanks a bunch, I've been banging my head for hours
generous-apricotā¢14mo ago
Without that default array state, you were sometimes passing in
Array<undefined>
. Having a named prop catches those kinds of bugs early on.
have a good weekend!optimistic-goldOPā¢14mo ago
Now to spend a couple hours figuring out what those changes actually did š
1st react project here
Have a good night!