Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't think the syntactic sugar works how you describe. JSX components actually desugar to something like:

   <b>{jsx(MyComponent, { attr: "yes" })</b>
(Previously this function was called "React.createElement", but these days they have special functions that only the JSX compiler is allowed to use.) The extra layer of indirection is needed to do things like support hooks being called inside of MyComponent's function body, keep track of `key` props, and so on.


I don't think that's true, you can write uncompiled createElement calls and everything still works fine.


createElement still exists, but the JSX compiler doesn't use it anymore; see https://legacy.reactjs.org/blog/2020/09/22/introducing-the-n...

Regardless of whether you use JSX or createElement, you can't just call MyComponent({ attr: “yes” }) directly, is the main point.


Yeah I don't think you ever could just call MyComponent(props) directly if the component used hooks. If it was hookless (what a concept...) it wouldn't matter.


You certainly can in Preact.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: