<Show> with number | null
What is the recommended way of using the
Show
component to conditionally render a number that can possibly be null? Currently, if you do the following, the number won't be rendered if its value is zero.
6 Replies
nullableValue() !== null
theres not much else you can do
if value is the nullable signal then{value()}
instead of the whole Show is enough, it wont render "null"I would argue
!== null
is actually the only truly correct thing to do (regardless of solidjs). Unfortunately, typescript eslint plugin does not warn about this because it does not know when
is a context where it should complain.
ok yeah, with callback form, it gets tricky indeedBut that makes it impossible to access the underlying number value without doing
nullableValue()!
which is an antipattern, I believe.you can wrap the typechecked value with something truthy inside
when
and then unwrap it in the callback
https://playground.solidjs.com/anonymous/4ef10b8e-d8b0-4522-a710-ed0fad01b959Thank you, looks interesting. It's a shame that all this complexity is required for such a basic thing, though.
FWIW,
NaN
part was what i introduced with getting the value from the input
in your case, it would be
if you really cares about being correct in terms of typescript, it's a good trade IMO, it's a limitation of typescript after all
keyed version