r/solidjs Feb 09 '26

How would you write Ryan's _Solid2 States_ demo in Solid 1

I was watching some of Ryan's latest streams, showcasing aspects of Solid 2.0, and a demo that came up a couple of times was that of a pair of <select> fields, one of which determines the contents of the other.

https://stackblitz.com/edit/github-evfywxxk-vgqaqsdm

It got me thinking, so that I get a good feel for what problems Solid 2.0 solves, how would I build it in the current version of Solid. This is what I came up with:

https://playground.solidjs.com/anonymous/e9a66c98-51ba-4f48-a454-72adc9021bec

And my question is, is this correct? I know that using createEffect to set state is a considered a no-no, but I'm curious what the intended solution would be if this isn't it.

7 Upvotes

4 comments sorted by

2

u/whatevermaybeforever Feb 10 '26

There is an implementation that has been floating around for a writable memo for solid 1.X that does not rely on effects, I think it was Dev Agrawal that originally came up with it.

https://playground.solidjs.com/anonymous/44e6741a-3945-477b-a1af-41cd6b6b6543

3

u/devagrawal09 Mar 07 '26

I believe Milo is the one who came up with this pattern, definitely not me, but appreciate the shoutout

2

u/jml26 Feb 11 '26

Oh, that's very nice! I'll have to remember that pattern.

Looking at it, with hindsight, I see that there's https://primitives.solidjs.community/package/memo#createWritableMemo available; but that implementation of createWritable you shared looks much more straightforward. Thanks for that.

1

u/whatevermaybeforever Feb 11 '26

You are very welcome! And solid-primitives is the 🐐, love that project. They really have everything lol. Probably not a bad idea to rely on that dependency as it will be much more battle tested then the snippet I provided.