Re:Solid.js feels like what I always wanted React to be
by thatswrong0 on Tuesday March 01, 2022 @01:41AM
(#30510480)
> The mechanism that enables code reusability is through composing components
If you think that this:
return (
<Apple>
{({ apple }) => (
<Slicer slice={apple}>
{({ sliced: slicedApple } => (
<DinnerPlane contents={slicedApple} />
)
}
</Slicer>
)}
</Apple>
);
is more desirable than this: const apple = useApple();
const slicedApple = useSlicer(apple);
return <DinnerPlate contents={slicedApple} />;
Then go for it I guess.Although you'd have to somehow ignore the fact that you'd end up with an even bigger mess if you want these intermediate functionality steps to interact with the parent component in a non-trivial way, ..
Needless to say, I have written such render-prop and "renderless" components in the past, and I see very little upside compared to hooks.
Re:Solid.js feels like what I always wanted React to be
by masterofmisc on Tuesday March 01, 2022 @02:20AM
(#30510736)
Thats interesting. So in your 2nd example, am I right in saying the variables 'apple' and 'slicedApple' are react JSX that you are ultimatly passing through to <DinnerPlate/> to render on the screen? If so, yes, that is fairly intuitive.
Re:Solid.js feels like what I always wanted React to be
by thatswrong0 on Tuesday March 01, 2022 @03:02AM
(#30511031)
'apple' and 'slicedApple' would more likely be strings / objects / arrays in the real world. Maybe this still woefully contrived version is clearer?
function FacebookComment({ commentId }) {
const comment = useGetComment(commentId);
const likes = useGetLikes(comment);
return (
<div>
<span>{comment.text}</span>
<span>{likes.length} likes</span>
</div>
);
}
I don't think deal with more braces right now to bring the alternative into existence unfortunately
Re:Solid.js feels like what I always wanted React to be
by masterofmisc on Tuesday March 01, 2022 @07:57AM
(#30513525)
Ohh i see. Yes, that makes sense. Thanks for taking the time to reply.
You’re using React. The mechanism that enables code reusability is through composing components.
There’s nothing wrong with class components even for the most complex logic. The only downside is the community has moved on and mostly adopted hooks and functional components.