remoteinterview / zero

Zero is a web server to simplify web development.
https://zeroserver.io/
Apache License 2.0
5.83k stars 242 forks source link

Are React Hooks supported? #18

Closed pca2 closed 5 years ago

pca2 commented 5 years ago

Do you support React Hooks yet? I copied and pasted the example code from the React website, however I was hit with an error:

Invariant Violation: Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)

at /private/var/folders/k0/fqr3001s20n5gmnh5tt7jsxm0000gn/T/zeroservertmp/31fdc6488b585a0e4ab331793601476d705eb1ae/hook.jsx(Example):5
1   import React, { useState } from 'react';
2
3   function Example() {
4     // Declare a new state variable, which we'll call "count"
5     const [count, setCount] = useState(0);
6
7     return (
8       <div>
9         <p>You clicked {count} times</p>
10        <button onClick={() => setCount(count + 1)}>
pavvo commented 5 years ago

What React version do you use?

pca2 commented 5 years ago

I don’t have React installed globally:

 npm list -g --depth=0

/usr/local/lib ├── axios@0.18.0 ├── eslint@5.13.0 ├── express-generator@4.16.0 ├── ijavascript@5.0.20 ├── mongodb-stitch-cli@1.1.0 ├── npm@6.5.0 └── zero@1.0.8 On Feb 28, 2019, 5:10 AM -0500, Pavle Vojinovic notifications@github.com, wrote:

What React version do you use? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

asadm commented 5 years ago

This is probably a zero related bug. Somewhere in ‘handler-react’ package. The error page says to check for multiple versions of react being loaded. The react handler does use it’s own react for SSR and the client build has it’s own React dependency.

I am looking into it today.

asadm commented 5 years ago

It looks like the problem only happens during the server render. Because if I render a dumb component and then change it to use hooks, the HMR-updated component works fine in the browser.

asadm commented 5 years ago

I have fixed this in the latest version. Have a look!

pca2 commented 5 years ago

👍 Looks good to me, thanks