3 ms·
Not having to import React is nice. It took me a bit to realize that it was necessary because the JSX was actually just React.createElement calls. When I teach
by hardwaregeek 6y ago
Not having to import React is nice. It took me a bit to realize that it was necessary because the JSX was actually just React.createElement calls. When I teach React I kinda gloss over it because explaining how JSX works is too confusing. But then forgetting to import it gives a confusing error for beginners.
I wonder what plans the React team has for JSX. I liked the prop forwarding style that ReasonReact had, but I guess that's not compatible.
- dceddia 6y ago> explaining how JSX works is too confusing This is interesting; I take the opposite approach, thinking that if I can help someone understand that JSX is merely fancy syntax on top of plain JS function calls, that React won't seem so "magical". I sometimes see comments like "I hate React's looping syntax" and it's clear that a lot of people get hung up thinking about React as a templating language. I can see how explaining that extra level of detail could be confusing though, especially right up front, and especially for developers who're simultaneously learning JS alongside React.
- frosted-flakes 6y agoI was reading through Crank.js's[1] documentation the other day, and I noticed that all of its examples explicitly set the JSX createElement function with a pragma comment. Like this: /** @jsx createElement */ import {createElement} from "@bikeshaving/crank"; import {renderer} from "@bikeshaving/crank/dom"; renderer.render(<div id="hello">Hello world</div>, document.body); [1]: https://crank.js.org/guides/getting-started https://crank.js.org/guides/getting-started