First I want to say, this is pretty neat! I think it would be pretty fun to try to write a wrapper around React that changes the way it works.
I don't really see this as something that should be adopted for real-world use though. The primary use-cases I see are (inspired by your 'Motivations' section in your readme):
Beginners who don't want to open a command line.
The hardest part about this is installing node. Then all you need to get started are 3 commands:
npx create-react-app my-app
cd my-app
npm start
Plus, if you're going to be working with JavaScript on any largish project, npm is very useful to know how to use.
And there's always CodeSandbox too if you really don't want to deal with the command line.
2. Beginners to React who are more familiar with UI frameworks more similar to SwiftUI.
This kinda feels like an excuse to not leave your comfort zone and really grow by learning the tool you're working with. I'm not saying that you are making that excuse (I'm sure you had to learn quite a bit of React to be able to make this library), but someone else who sees this library and decides to use it.
From a readability standpoint I understand the friction of having to learn a new syntax. I've totally looked at libraries like SwiftUI before and thought, "Man, I wish they had a syntax more like jsx, because that would be easier to read and use!" I think it's more about what you're familiar with rather than one being inherently more readable than the other.
3. Sprinkling some react into a JavaScript-light website.
I see this as the most viable use-case. It is a little more ergonomic than directly using createElement.
Other Notes
One decision you made in particular bugs me. Correct me if I'm wrong, but the example makes it look like you could do this:
// Contrived example
const SubmitButton = (onClick, props) =>
View('button')(props.alternateLabel || 'Submit')
.set({ onClick });
// Usage
SubmitButton(handleClick)
.set({ alternateLabel: 'Send' });
```
So we have our primary-ish props passed in directly as arguments and then we have some other props that we can use with `set`. I think the reason this bugs me is that it isn't how React actually works. I see how that can be a useful tool in a UI framework in general, but it doesn't seem like it belongs in React.
And since I'm seeing the primary use cases being people new to React, it obfuscates how React actually works and presents a barrier when someone decides, "Now it's time to learn React for real".
---
So this got a lot longer than I expected it to, but that's my feedback. Overall, it's a cool project. :)
Thank you so much for the thoughtful feedback. You make a lot of really great points. This was an idea that struck me and I mostly want to see if it’s viable. As you say, there are realistic challenges and I’m not sure if this works or is realistic for a production app but I’d like to think it’s perfect for prototyping, small projects, or quick hacks.
As for your gripe with using props I think you’d be pleased to know View does allow for assigning the props object upfront:
4
u/Aeron91 Jul 28 '19
First I want to say, this is pretty neat! I think it would be pretty fun to try to write a wrapper around React that changes the way it works.
I don't really see this as something that should be adopted for real-world use though. The primary use-cases I see are (inspired by your 'Motivations' section in your readme):
Beginners who don't want to open a command line.
The hardest part about this is installing node. Then all you need to get started are 3 commands:
Plus, if you're going to be working with JavaScript on any largish project, npm is very useful to know how to use.
And there's always CodeSandbox too if you really don't want to deal with the command line.
2. Beginners to React who are more familiar with UI frameworks more similar to SwiftUI.
This kinda feels like an excuse to not leave your comfort zone and really grow by learning the tool you're working with. I'm not saying that you are making that excuse (I'm sure you had to learn quite a bit of React to be able to make this library), but someone else who sees this library and decides to use it.
From a readability standpoint I understand the friction of having to learn a new syntax. I've totally looked at libraries like SwiftUI before and thought, "Man, I wish they had a syntax more like jsx, because that would be easier to read and use!" I think it's more about what you're familiar with rather than one being inherently more readable than the other.
3. Sprinkling some react into a JavaScript-light website.
I see this as the most viable use-case. It is a little more ergonomic than directly using
createElement.Other Notes
One decision you made in particular bugs me. Correct me if I'm wrong, but the example makes it look like you could do this: