Comment by Aeolun

5 years ago

But what does ‘#await someFetch’ actually do? The thing I like most about react is that it’s just executing plain Javascript most of the time.

> The thing I like most about react is that it’s just executing plain Javascript most of the time.

Then explain what hooks do ;)

Hooks are decidedly not Javascript (even if they look like Javascript), and are a much more weird construct than {#await promise}

  • No, they are JavaScript, it is array based programming wrapped in a reactive functional-declarative approach. Simply array of objects cascading with state. {#await promise} is more cryptic than any useHook function implementation.

    • > No, they are JavaScript, it is array based programming wrapped

      Javascript has no support for array-based programming.

      So, hooks are not Javascript: they look like regular function calls, but:

      - they can only be declared and called before rendering

      - they can't be called out of order

      - they cannot be called conditionally

      - they have to be called a specific name to be handled correctly by React runtime

      - some (but not all of them) require dependency lists that determine how they are invoked

      > {#await promise} is more cryptic than any useHook function implementation.

      usEffect documentation is something like 20 pages long. The use of {#await promise} is immediately understandable from the code example, and its entire documentation fits on a page and a half

      3 replies →

Not just most of the time — all of the time! JSX is converted to plain JS (react.createElement) before it gets to the browser.

  • Isn't it actually the opposite? Svelte code is compiled to plain JS whereas React has a large runtime.

    • Nah, JSX also gets converted to Javascript. The difference is in that the React runtime re-renders whole components every time something changes, and Svelte is more granular about it even during the compilation step.