Hacker News new | ask | show | jobs
by ryansolid 13 days ago
You've always been able to early return in Solid it just was never going to do what you expected because components run once. That's not something to fix. A language can look at `if` and say that's a `<Show>` component, but effectively its wrapping the choice in the templating(reactive expression). It doesn't really matter because those templates run once too so nesting is fine. But ultimately supporting it is supporting sugar not much else.
1 comments

> it just was never going to do what you expected

Yeah that's what I mean.

A lot of my react components start out with the equivalent of

  if (state==error) return <p>error</p>;
  if (state==loading) return <p>loading</p>;
  if (!connection) return <p>offline</p>;
  if (admin) return <Redirect/>;
doing that with <Show /> (and passing the function so TypeScript still works) means the conditions take 20 lines instead of 4, and the meat of my component is indented an extra 8 levels.