by ng12 · 6y ago · 0 comments
const Counter = () => {
const [count, setCount] = React.useState(0)
return (
<div>
<p>You have clicked the button {count} times.</p>
<button onClick={() => setCount(count => count + 1)}>Increment</button>
</div>
)
}
Replace the atom/swap with a useState hook and it's almost identical.useState returns 2 variables - a getter and a setter, where the getter is just a variable and not even a function to call.
How is that equatable to some hidden construct? How is Clojure superior to that?
import {createElement as h} from "react"
const Counter = () => {
const [count, setCount] = React.useState(0)
return h("div", {},
h("p", {}, `You have clicked the button ${count} times`),
h("button", {onClick: () => setCount(count => count + 1)}, "Increment")
)
}
There are additionally libs like hyperscript (https://github.com/mlmorg/react-hyperscript) that take the non-JSX approach further. Although honestly, I don't recommend it. JSX is really great even it seems a little unfamiliar.The '1 language' version requires you to learn language-specific syntax for creating HTML elements.
How is that more compelling?