r/reactjs • • Jul 28 '19

Show /r/reactjs ScriptUI: Write React without JSX

https://github.com/anater/ScriptUI
3 Upvotes

26 comments sorted by

View all comments

1

u/[deleted] Jul 28 '19

Hi /r/reactjs!

I'm the author of ScriptUI. I whipped it up over the last few weekends as a proof of concept. I'm looking for feedback on whether you'd use something like this. I hope it helps make starting projects easier.

Thanks for reading!

4

u/friendshrimp Jul 28 '19

One thing that JSX gives us is named properties. I see this being useful if you are only passing a few props but as soon as you pass more than a few you’d have a confusing looking list of Paramus passed to a function.

1

u/[deleted] Jul 28 '19

That's a great point! Thanks for checking it out. I like to think there's still room for this through the use of an object literal or by leveraging modifiers.

For example:

// Object
const Button => ({ label, onClick }) => View("button", { onClick })(label);

// Modifier
const Button => ({ label, onClick }) => View("button")(label).set({ onClick });

// Custom Modifier for onClick is possible too
const Button => ({ label, onClick }) => View("button")(label).onClick(onClick);

// JSX
const Button => ({ label, onClick }) => <button onClick={onClick}>{label}</button>;

0

u/[deleted] Jul 28 '19

[deleted]

1

u/[deleted] Jul 28 '19

Good question! Thanks for checking this out. I don’t have a bunch of examples but I see how that could be helpful.

The friction is in the required tooling to use JSX. Node, npm, Babel. Without that tooling, you can use React.createElement. But that’s too long so you’ll need some alias. const h = React.createElement but this gets noisy because your element type, props, and children are all jammed into a single function call. So the abstraction is meant to break up the component definition more cleanly. This is inspired by how SwiftUI defines UI.

3

u/DeadPlutonium Jul 28 '19

Lotta respect for building a mini-API or new approach to solve tooling difficulties, must have been a good project to learn from if nothing else!