Repository navigation
Description
Hey, I'm a total PS newbie, so I'm kinda lost in all of the purescript react options. There are the following libraries:
purescript-reactpurescript-react-basic-classicpurescript-react-basic-hooks
There's mutiple comparison points between them, and I'm unsure in all of those points. Here I list my presumptions. Could somebody experienced with this library (-ies) shine some light on this and provide some proper comparisons?
Power
purescript-simple is just a base library for the -classic and -hooks implementations. It doesn't do anything by itself.
All of the rest are equivalent in 'power' — all are standalone React libraries that you can use to use external React components or write your own (in purescript). Not sure if you can write your own hooks with the -hooks lib.
Types
AFAIK purescript-react doesn't have typed props and elements (i.e. you can pass a href attribute to a div), not sure if react-basic-X is different.
Biggest issues
Why are the libraries struggling with? purescript-react seems to want to implement hooks (for a few years now), and lack of typed props also seems like a problem (at least to me), while purescript-simple's current biggest ambition seems to be adding proper documentation.
The implementations of purescript-simple seem to be documented, but rather sparsely (relying probably on the React docs) and don't have (m)any examples. Not sure if those libraries are feature-complete, at least when it comes to the common React use-cases, but it seems like it. The docs would then be the biggest problem.
Custom components
When it comes to creating custom components (i.e. not being limited to the default html ones) I think you can do this in all three, but purescript-react and purescript-react-basic-classic presumably generate class-based ones, and purescript-react-basic-hooks function-based ones. Not sure if that affects anything besides the generated JS (which shouldn't matter in 99% cases).
Activity
maddie927 commentedon Feb 1, 2021
Hi @Eugleo, welcome to PS!
I'm not sure what you mean by
purescript-simple. It sounds like you're describingpurescript-react-basic, but there's also an oldpurescript-react-simplelibrary which I don't believe still works with recent PureScript compliers. I'm going to assume the former for the rest of this.react(omitting thepurescript-prefixes from here on) was the first React library for PureScript. It as built before hooks existed and can sometimes be fairly verbose when you need to work with React's class lifecycles. It also has the prop shortcomings you mentioned above. It may have changed a bit since then, I haven't kept up with it much since we started usingreact-basic.react-basicwas created a few years ago to avoid some of the ceremony around converting JS React components to PS. It had some problems but it mostly worked for our use cases, and it introduced theUniontrick for making DOM components with optional props. The original version of this API doesn't exist anymore, but versions 2, 3, and 4 are still available, and will all be indefinitely.If you go the
react-basicroute, you can mix and match the available APIs.react-basicwas split out into two implementations:react-basic-hooksandreact-basic-classic. If you want hooks,react-basic-hooksis the only option I know of.react-basic-classicis closer to the originalreactlibrary mentioned above, or Reason-React if you're familiar with that. It builds off of React's class-based API. But bothreact-basic-hooksandreact-basic-classicuse the sameReactComponentandJSXtypes, so you can define components using both in the same project.If you're starting from scratch, I recommend
react-basic-hooks. You don't need to install anything else explicitly, as it depends onreact-basic. It's very close to the JS React hooks API, making it easy to translate code and concepts, as well as make use of existing JS React hooks. This slightly makes up for the terrible documentation (it's mostly "do it how you'd do it in JS hooks"), but it's definitely still an issue we should address someday. The next branch of lumihq/react-basic-starter was meant to be an updated docs/demo/starter repo for all this, but I've been putting it off for a long time. In the meantime I'm happy to answer questions if you have any.Regarding your last question about custom components,
react-basic, both-hooksand-classicallow JS interop. You'll want to use theReactComponent {props}type if you're usingforeign importto pull in a JS React component. To create components in PS which are meant to be consumed in JS, look for the functions which returnReactComponent. With-hooks, each component function has aReactComponentvariant, likecomponentandreactComponent. With-classic, you'd usetoReactComponentto wrap a component created withmakeormakeStateless. I'm not sure what the correct way to do this inreactis but I'm sure there's something similar.