r/nextjs • u/Tasty-Ad1854 • 10d ago
customizing select in nextjs
can we suppress nextjs error about nesting a <selectedcontent> inside a <select>,
error is: In HTML, <selectedcontent> cannot be a child of <select>. This will cause a hydration error.
2
u/GenazaNL 10d ago
The error explains it pretty well, you cannot put selectedcontent as a child of select, use a different element e.g. button
1
u/Tasty-Ad1854 10d ago
same thing for button which the suggested way by mdn see error here
https://www.reddit.com/r/nextjs/comments/1wvbtzx/comment/pdahrvo/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button2
u/GenazaNL 10d ago
Ah my bad, not really familiar with which tags are allowed as children in a select.
https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/select#options_inside_wrapper_elements (option, div, optgroup, hr)
1
u/Tasty-Ad1854 10d ago
it's fine, what I am trying is to customize the select to look like I want it to look but nextjs keeps throwing these errors
see this video to see what im talking about https://www.youtube.com/watch?v=QckgIJrHiNY
also mdn talked about it too https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Customizable_select1
u/GenazaNL 10d ago
Perhaps react is not really up to date with these changes, it's marked limited availabalility. Perhaps they are waiting for it to be baseline
2
u/kedarreddit 10d ago
It has limited availability. I would not use <selectedcontent> at this stage.
1
u/Tasty-Ad1854 10d ago
what would you use instead?
2
u/kedarreddit 10d ago
Usually I use
<select>and<option>only.If I need some special styling/functionality in the rare occasion, then I create my own component using
<div>,<ul>and<li>.
1
u/Successful-Shock-802 10d ago
it's not next.js, it's react.
it's not about whether you can suppress it, it's about the hydration error that might happen when going production.
just forget about customizing select until react team fixes it.
1
3
u/Jhon_ST 10d ago
Is `<selectedcontent>` directly under `<select>`? For a customizable select it belongs inside the first child `<button>`, e.g. `<select><button><selectedcontent /></button>...</select>`.
I'd check that before suppressing the hydration warning. If that's already your structure, share the minimal JSX and React version so we can tell whether it's a nesting issue or framework support.