S
SolidJS•2mo ago
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")!);
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
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
20 Replies
REEEEE
REEEEE•2mo ago
Wrap the return of Btn in a fragment
siduck
siduckOP•2mo ago
i hate the new solid changes 😭
REEEEE
REEEEE•2mo ago
What new changes?
siduck
siduckOP•2mo ago
it used to work before now nothing is reactive
const Btn = (props: any) => {
return props.open ? <button>test</button> : null
}
const Btn = (props: any) => {
return props.open ? <button>test</button> : null
}
like that?
REEEEE
REEEEE•2mo ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
REEEEE
REEEEE•2mo ago
Afaik this is how it always worked Stuff is only reactive in JSX, effects, or memos
siduck
siduckOP•2mo ago
so this wont work right?
No description
REEEEE
REEEEE•2mo ago
No Destructuring and early returns never worked
siduck
siduckOP•2mo ago
how do you destructure then splitprops seems so confusing
siduck
siduckOP•2mo ago
syntax looks so weird too
No description
siduck
siduckOP•2mo ago
like why would one here not just use props.name here? so many mental gymnastics
REEEEE
REEEEE•2mo ago
It's useful for not passing the greeting and name to the h3 you could just use props.name, it's just showing you that greting and name are put into the local object
siduck
siduckOP•2mo ago
cant i destructure anymore
siduck
siduckOP•2mo ago
ig i cant use this syntax anymore
No description
siduck
siduckOP•2mo ago
cuz all of this will also run even if the dialog is closed
No description
REEEEE
REEEEE•2mo ago
You could wrap it in another component I guess Destructuring never worked without a plugin, idk if you're thinking of something else
siduck
siduckOP•2mo ago
sad :/ it works in all other frameworks ig i'll never update solidjs version for nvchad.com
REEEEE
REEEEE•2mo ago
What version are you on right now?
siduck
siduckOP•2mo ago
1.8
siduck
siduckOP•2mo ago
GitHub
nvchad.github.io/package.json at main · NvChad/nvchad.github.io
Site for NvChad built using solidjs + unocss. Contribute to NvChad/nvchad.github.io development by creating an account on GitHub.

Did you find this page helpful?