3 ms·
You've given this example about how to use React without JSX but actually you're not using React but Preact, which is a different library. Preact, to its credit
by actinium226 1y ago
You've given this example about how to use React without JSX but actually you're not using React but Preact, which is a different library. Preact, to its credit, actually has instructions for using it without JSX right in their getting started guide: https://preactjs.com/guide/v10/getting-started/#alternatives-to-jsx https://preactjs.com/guide/v10/getting-started/#alternatives.... In fact it's the very first paragraph.
React itself buries this information in a reference (https://react.dev/reference/react/createElement#creating-an-element-without-jsx https://react.dev/reference/react/createElement#creating-an-...), and the reference doesn't even give a complete example because the example still uses JSX to render the root component.
And I'm not sure if Preact is really a viable alternative to React. If a library I want to use can't work via preact/compat, what then? Do stackoverflow solutions for React problems apply to Preact? I imagine at least some might not. Given these limitations, is there a reason someone would choose Preact over a framework that has its own ecosystem, like Vue for example?
- b_e_n_t_o_n 1y agoPreact is basically a clone of React, you could replace those imports with React and you'd have the same app. Preact's compatibility layer is good but not perfect - some UI libraries rely on React's internal implementation which breaks with Preact. I think people can and should chose Preact for when they know what third party dependencies they will rely on, and for situations like this where it's a fairly trivial single page app.