WIP fix #171 Convert react integration to use hooks#186
Open
lkmill wants to merge 1 commit intodevelopit:masterfrom
Open
WIP fix #171 Convert react integration to use hooks#186lkmill wants to merge 1 commit intodevelopit:masterfrom
lkmill wants to merge 1 commit intodevelopit:masterfrom
Conversation
| * @connect( state => ({ foo: state.foo, bar: state.bar }) ) | ||
| * export class Foo { render({ foo, bar }) { } } | ||
| */ | ||
|
|
| 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.
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.
Suggested change
| 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.
Suggested change
| }, []); | |
| }, [store]); |
Might want to at least put the store in here
maybe props as well?
|
Super old PR lol 🙃 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.