-
Notifications
You must be signed in to change notification settings - Fork 85
fix(use-observable): store subjects into state directly #4
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
TotooriaHyperion
commented
Nov 22, 2018
@Brooooooklyn this instantiate a Subject every render(first mount & update). It's not performant.
Not sure whether it's better to change code here or open an issue to react for using a callback to return the initial state.
const [state] = setState(() => new BehaviorSubject());
It seems that this pattern has been implemented internally.
https://github.com/facebook/react/blob/master/packages/react-reconciler/src/ReactFiberHooks.js#L337
but I guess the cost of initializing a function every render is quite same as initializing a BehaviorSubject. Not very sure about it, need some more tests.
useObservable
.