Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional Rendering with Run Fails When Returning Components #8

Open
erwinheldy opened this issue Dec 12, 2024 · 0 comments
Open

Comments

@erwinheldy
Copy link

For example:

import { Run, useSignal } from 'solid-react';

export default function App() {
  const [count, setCount] = useSignal(0);
  const inc = () => setCount((count) => count + 1);
  const dec = () => setCount((count) => count - 1);

  return (
    <>
      <button onClick={dec}>-</button>
      {count()}
      <button onClick={inc}>+</button>

      <hr />
      {/* This works */}
      {Run(() => (count() > 10 ? 'High' : 'Low'))}

      <hr />
      {/* This works */}
      {Run(() => (count() > 10 ? <High /> : 'Low'))}

      <hr />
      {/* This doesn't work */}
      {Run(() => (count() > 10 ? <High /> : <Low />))}
    </>
  );
}

function High() {
  return <h1>High</h1>;
}

function Low() {
  return <h1>Low</h1>;
}

Demo: https://stackblitz.com/edit/vitejs-vite-nzvjm9ji?file=src%2FApp.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant