Next.js Discord

Discord Forum

Tables and paragraphs

Answered
In&Out posted this in #help-forum
Open in Discord
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?
View full answer

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
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
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
One second
Plott Hound
I can’t help if I don’t see some errors or code
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-error
Error: 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 me
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>
@Plott Hound also sharing the `<Columns>` component would help me
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;
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
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
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
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
<p>
something
<p>another thing</p
</p>

this is incorrect
Eh idc i dont use it no more
Should I use divs then, instead of tablse
tables
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
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
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
Does the syntax even matter lol
Plott Hound
yes
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
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
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
Sure boss
Plott Hound
see the first reply to your post
basically right click my message -> apps -> mark as solution
lol
@Plott Hound basically right click my message -> apps -> mark as solution
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
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?
No I right clicked the bot message ahahahah
Dumb me
oh lol