S
SolidJS5mo ago
mizark

<For> throws hydradtion error with a <span> as fallback element

This fails
<>
<div id="products-container">
<For each={props.products()} fallback={<span>loading</span>}>
{(product, i) => {
debugger;
return (
<ProductItem product={product} key={`${i()}-${product.id}`} />
);
}}
{/* {(product, i) => (
<div style={{ background: "red" }}>product {i()}</div>
)} */}
</For>
</div>
</>
<>
<div id="products-container">
<For each={props.products()} fallback={<span>loading</span>}>
{(product, i) => {
debugger;
return (
<ProductItem product={product} key={`${i()}-${product.id}`} />
);
}}
{/* {(product, i) => (
<div style={{ background: "red" }}>product {i()}</div>
)} */}
</For>
</div>
</>
This works
<>
<div id="products-container">
<For each={props.products()} fallback="loading">
{(product, i) => {
debugger;
return (
<ProductItem product={product} key={`${i()}-${product.id}`} />
);
}}
{/* {(product, i) => (
<div style={{ background: "red" }}>product {i()}</div>
)} */}
</For>
</div>
</>
<>
<div id="products-container">
<For each={props.products()} fallback="loading">
{(product, i) => {
debugger;
return (
<ProductItem product={product} key={`${i()}-${product.id}`} />
);
}}
{/* {(product, i) => (
<div style={{ background: "red" }}>product {i()}</div>
)} */}
</For>
</div>
</>
Seems like a bug but maybe I am doing something wrong?
2 Replies
Madaxen86
Madaxen865mo ago
Had the same problem. I updated to the latest version of solid-js 1.18.19. Now it works. Instead of key like in react you may want to use something like data-index={...} as there is not key attribute in solidjs jsx
mizark
mizarkOP5mo ago
Yeah that worked
Want results from more Discord servers?
Add your server