SolidJSS
SolidJS6mo ago
31 replies
siduck

How to make props reactive?

Hi why isnt the props reactive there, in Btn component? I hope i dont have to use a module for this now :/

import { render } from "solid-js/web";
import { createSignal } from "solid-js";

const Btn = (props: any) => (
  props.open ? <button>test</button> : null
);

function Counter() {
  const [open, setOpen] = createSignal(false);

  return (
    <div>
    {String(open())} 
    <br/> 
    <button onClick={() => setOpen(!open())}> toggle </button>
    <br/>
    <Btn open={open()}/>
  </div>
  );
}

render(() => <Counter />, document.getElementById("app")!);


https://playground.solidjs.com/anonymous/00f4000c-2b99-413f-b393-0a9504cc6f14
Quickly discover what the solid compiler will generate from your JSX template
Was this page helpful?