Tables and paragraphs
Answered
In&Out posted this in #help-forum
In&OutOP
Hey folks, why sometimes, actually most of the time, when I use p and table tags, I'd get hydration errors, and usually the fix is to use a div tag
Answered by Plott Hound
Without seeing the code it sounds like you have some incorrect syntax. Do you have p tags inside other p tags?
80 Replies
Plott Hound
Without seeing the code it sounds like you have some incorrect syntax. Do you have p tags inside other p tags?
Answer
@Plott Hound Without seeing the code it sounds like you have some incorrect syntax. Do you have p tags inside other p tags?
In&OutOP
In this case, only tables, <table> , <tr and th and colgroup
And code is too big, it's confusing
I just removed all those tags and added div, and it worked but still, I wanted table tags
Plott Hound
Can you share the code here or on GitHub?
Can you double check your table syntax? It’s quite strict
In&OutOP
Yup it works all well
Instead of that, what would fix hydration errors?
Would useEffect help, the mounting thingy
the window !== undefined
Plott Hound
Share the exact error you are getting
In&OutOP
One second
Plott Hound
I can’t help if I don’t see some errors or code
In&OutOP
Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching <table> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-errorError: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.And code...
Plott Hound
thanks
just to clarify.. if you change the table to divs you dont get hydration errors?
also sharing the
<Columns> component would help meside note - you should be using the second parameter of
map to have unique keys, currently your keys are not unique which is a problem. fix:<tbody>
{[1, 1, 1, 1, 1, 1, 1, 1].map((item, index) => (
<Columns
order="#8786"
date="January 5, 2024"
status="Paid"
total="$1500"
action="View Details"
key={index} // Use the index as the key
/>
))}
</tbody>@Plott Hound side note - you should be using the second parameter of `map` to have unique keys, currently your keys are not unique which is a problem. fix:
<tbody>
{[1, 1, 1, 1, 1, 1, 1, 1].map((item, index) => (
<Columns
order="#8786"
date="January 5, 2024"
status="Paid"
total="$1500"
action="View Details"
key={index} // Use the index as the key
/>
))}
</tbody>
In&OutOP
Sure, thanks
@Plott Hound also sharing the `<Columns>` component would help me
In&OutOP
interface Iprops {
order: string;
date: string;
status: string;
total: string;
action: string;
}
function Columns({ order, date, status, total, action }: Iprops) {
return (
<tr>
<td>{order}</td>
<td>{date}</td>
<td>{status}</td>
<td>{total}</td>
<td>
<button>{action}</button>
</td>
</tr>
);
}
export default Columns;In&OutOP
Do you need anything else?
Or can I just turn everything into div
Plott Hound
your table syntax is correct
a hydration error is when the content between server and client differs
i cant see anything in what you shared that would cause that especially considering you are using static dummy data
In&OutOP
I want to know, why do tables do this
Plott Hound
to debug this further i'd need a minimal reproduction repo on github so i can test it out locally
In&OutOP
It's so add
odd
Plott Hound
i use tables on a daily basis for years now and never had a hydration issue
its very strange
@Plott Hound to debug this further i'd need a minimal reproduction repo on github so i can test it out locally
In&OutOP
Thats' literally all the code
I had hydration errors with p tag as well lmao
Idk if im just mindblowingly bad or what ahahahha
Discovering game breaking bugs because of how bad I am
Plott Hound
p tag will do it if you have them inside each other eg
this is incorrect
<p>
something
<p>another thing</p
</p>this is incorrect
Plott Hound
i guess if its working for you with divs do that. but if you want me to fix the table issue make a minimal repo i can download and test locally so i can fix it
In&OutOP
Before I do, do I even need tables?
Plott Hound
tables are better to use but if you want to avoid anymore holdups just use divs and try again later
In&OutOP
Do they have a specific purpose
Plott Hound
you dont need tables but it is the correct syntax to use for this kind of data
div will work fine and users wont even know the difference
In&OutOP
Does the syntax even matter lol
Plott Hound
yes
In&OutOP
Tbh I kinda need speed on this so yeah
Does it matter
Plott Hound
i would just keep going with divs for now
but tbh it sounds like you have deeper issues in this project if you are getting hydration issues from tables and p's
In&OutOP
I'm just afraid of having security issues mainly
Plott Hound
i just cant diagnose it without seeing everything at this point sorry
using div over table will not introduce any security issues
In&OutOP
Fine, that's all I needed to know
Thanks man, I'll let you know if I have a switch up
Plott Hound
yeah feel free to reply to this with the repo if you want me to have a go
for now just mark it as solved if you want
In&OutOP
Sure boss
@Plott Hound for now just mark it as solved if you want
In&OutOP
How to mark it
Plott Hound
see the first reply to your post
basically right click my message -> apps -> mark as solution
In&OutOP
lol
Plott Hound
@riský can you check this?
sorry to tag you
...
@In&Out Click to see attachment
what message did you want to select
@riský what message did you want to select
In&OutOP
I apologize
Thanks
Plott Hound
thank you @riský sorry to bother you
ok ok, thats good, but i do wonder what happend... was it just retrying again that fixed?
In&OutOP
No I right clicked the bot message ahahahah
Dumb me
oh lol