yesmeck / react-with-hooks

[OUTDATED]Ponyfill for the React Hooks API (Support RN)
https://codesandbox.io/s/olx6zp44n6
MIT License
152 stars 11 forks source link

bring up to date with React v.16.8.0 (stable hooks release) #4

Open derrickbeining opened 5 years ago

derrickbeining commented 5 years ago

Great work on this! I'm hoping to use it in an upcoming react-native project at work while we wait for hooks to be released for RN, which apparently won't be making it in for another month or longer.

The stable release of hooks is due to land on February 4 with some breaking changes from the 16.7.0 alpha releases. Those changes are summarized here.

Do you have any sort of timeline for bringing this library up to date with it? Either way, are you open to accepting PR's, in case I find time to work on it?

yesmeck commented 5 years ago

Thanks for bringing this up, I'll take a look in these days.

derrickbeining commented 5 years ago

Good to hear! Got an additional question for you that I couldn't figure out just from looking at the code:

I noticed on the README of react-with-hooks that useEffect and useLayoutEffect are the same thing, which means one of them does not behave like its counterpart in the official react hooks (since according to the docs, useEffect runs after useLayoutEffect and after the render/paint phase. Could you share which one is not implemented correctly and what constraints prevent it from being implemented correctly?

From looking at the code, my guess is that useEffect isn't implemented correctly yet, since it's run in componentDidMount and componentWillUnmount.

yesmeck commented 5 years ago

No, useLayoutEffect isn't implemented. It's impossible to implement it form user side.

derrickbeining commented 5 years ago

Are you sure? That doesn't sound right. According to the docs:

useLayoutEffect fires in the same phase as componentDidMount and componentDidUpdate

Whereas, for useEffect it says:

Unlike componentDidMount and componentDidUpdate, the function passed to useEffect fires after layout and paint, during a deferred event ... Although useEffect is deferred until after the browser has painted, it’s guaranteed to fire before any new renders

That suggests to me that useEffect is the one that is not able to be implemented correctly, not useLayoutEffect. Right?

(Thanks, by the way, for your responsiveness)

yesmeck commented 5 years ago

You are right! I misunderstood the document, this page said:

If you’re familiar with React class lifecycle methods, you can think of useEffect Hook as componentDidMount, componentDidUpdate, and componentWillUnmount combined.

So I always think useEffect fires in the same phase as componentDidMount and componentDidUpdate.

Thanks for your correction.

yesmeck commented 5 years ago

I've ported the official tests of hooks to this repo, but some tests cannot be passed due to some reasons (39 passed, 15 failed). Need more efforts to make the tests passed.