Coder Social home page Coder Social logo

strange hydration mismatch about solid HOT 3 CLOSED

teidesu avatar teidesu commented on June 12, 2024
strange hydration mismatch

from solid.

Comments (3)

birkskyum avatar birkskyum commented on June 12, 2024 1

@teidesu , so the JSX should be returned in a function like this:

interface TextTableProps {
  items: {
    name: string;
    value: () => JSX.Element;
  }[];
}

and then the value can be set as:

value: () => (
              <>
                foo<div>div</div>
              </>
            ),

and used in a template as:

<div>
  {item.name}: {item.value()}
</div>

from solid.

birkskyum avatar birkskyum commented on June 12, 2024

solid start example of same error

from solid.

ryansolid avatar ryansolid commented on June 12, 2024

It's that you are recreating the items every time you access the prop. We evaluate expressions lazily. In so you are creating DOM elements that haven't been inserted in the DOM and when the client tries to find them they aren't there. So the error is correct and by design.

We recommend using children helper(https://docs.solidjs.com/reference/component-apis/children) if you wish to read children outside of the JSX and use them multiple places.

  const propItems = children(() => props.items).toArray();
  const maxNameLength = createMemo(() =>
    Math.max(...propItems.map((item) => item.name.length))
  );

  const items = () =>
    propItems.map((item) => (
      <div>
        {item.name}: {item.value}
      </div>
    ));

This will not have any issue. Alternatively you can have the JSX in the passed in template be created lazily itself by wrapping it in a function as suggested above.

from solid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.