-
Notifications
You must be signed in to change notification settings - Fork 139
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
WIP fix #171 Convert react integration to use hooks #186
base: master
Are you sure you want to change the base?
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.
lgfm
@@ -18,41 +16,34 @@ const CONTEXT_TYPES = { | |||
* @connect( state => ({ foo: state.foo, bar: state.bar }) ) | |||
* export class Foo { render({ foo, bar }) { } } | |||
*/ | |||
|
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.
return Child => function Wrapper (props) { | ||
const store = useContext(Context); | ||
let [state = mapStateToProps(store ? store.getState() : {}, props), setState] = useState(); | ||
boundActions = boundActions || actions ? mapActions(actions, store) : { store }; |
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.
I think useMemo
would be a lot better here, this seems way too likely to break
let boundActions; | ||
return Child => function Wrapper (props) { | ||
const store = useContext(Context); | ||
let [state = mapStateToProps(store ? store.getState() : {}, props), setState] = useState(); |
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.
let [state = mapStateToProps(store ? store.getState() : {}, props), setState] = useState(); | |
let [state, setState] = useState(mapStateToProps(store ? store.getState() : {}, props)); |
return (Wrapper.prototype = Object.create(Component.prototype)).constructor = Wrapper; | ||
|
||
return store.subscribe(update); | ||
}, []); |
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.
}, []); | |
}, [store]); |
Might want to at least put the store
in here
maybe props as well?
Super old PR lol 🙃 |
To fix #171 and not use any UNSAFE_ methods, i converted the react integration to use hooks.
I haven't updated the tests yet, want to hear whether this is an acceptable change first.
Besides removing the warnings, this also greatly reduces the build file sizes:
Before:
With some code golf, eg not using array destructuring, it is quite simple to reduce the size further but the code becomes less readable.