Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useMutableSource: allow getSnapshot to return a function #18823

Closed
dai-shi opened this issue May 4, 2020 · 3 comments · Fixed by #18933
Closed

useMutableSource: allow getSnapshot to return a function #18823

dai-shi opened this issue May 4, 2020 · 3 comments · Fixed by #18933
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@dai-shi
Copy link
Contributor

dai-shi commented May 4, 2020

Ref: reactjs/rfcs#147 (comment)

React version: 0.0.0-experimental-e5d06e34b

Steps To Reproduce

  1. createMutableSource that contains functions
  2. getSnapshot returns one of the functions

Link to code example:

https://codesandbox.io/s/jovial-dew-1eg4t?file=/src/App.js

The current behavior

If getSnapshot returns a function, it will run the function in render. This results in various errors.

My workaround: return an object wrapping a function, and destruct on caller.

For now, you can work around this by returning a function that returns your function

I don't know how this works as workaround.

The expected behavior

It would be nice if returning a function just works.

Note: this is not a rare use case in my library https://github.com/dai-shi/use-context-selector
because we often pass [state, setState] in a context value.

@dai-shi
Copy link
Contributor Author

dai-shi commented May 21, 2020

Thanks. Understood. I'd try not-100%-safe workaround in my lib, or let the lib users do a workaround.

@bvaughn
Copy link
Contributor

bvaughn commented May 22, 2020

Thanks for understanding!

@dai-shi
Copy link
Contributor Author

dai-shi commented May 22, 2020

(For those who might come here later,) here's my workaround: dai-shi/use-context-selector@2fcf1a2#diff-f41e9d04a45c83f3b6f6e630f10117fe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants