-
Notifications
You must be signed in to change notification settings - Fork 68
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
CPLAT-8037 Implement/Expose useReducer Hook #232
Conversation
# Conflicts: # example/test/function_component_test.dart
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.
+10
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.
Some typing comments but otherwise looks perfect! Also looks like there are some merge conflicts 😢
lib/hooks.dart
Outdated
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usereducer>. | ||
class ReducerHook { | ||
/// The first item of the pair returned by [React.userReducer]. | ||
Map _state; |
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.
State/actions don't have to be maps, do they? If not, this class should use generics:
class ReducerHook<TState, TAActions> {
TState _state;
void Function(TActions ) _dispatch;
}
as should the useReucer* functions
lib/hooks.dart
Outdated
/// ``` | ||
/// | ||
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#lazy-initialization>. | ||
ReducerHook useReducerLazy<T>(Map Function(Map state, Map action) reducer, dynamic initialArg, Function init) => |
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.
Init could be typed more specifically than just Function
# Conflicts: # example/test/function_component_test.dart # lib/hooks.dart # lib/react_client/react_interop.dart # test/hooks_test.dart
b7cab0d
to
d65d845
Compare
# Conflicts: # example/test/function_component_test.dart
# Conflicts: # lib/hooks.dart # lib/react_client/react_interop.dart # test/hooks_test.dart
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.
+10
/// final state = useReducer(reducer, {'count': 0}); | ||
/// | ||
/// return react.Fragment({}, [ | ||
/// state.state['count'], |
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.
#nit having state.state
is a little confusing; I wonder if we could come up with a different name for the hook return value...
store
? 😄 🤷♂ Nah, that's probably not better...
lib/hooks.dart
Outdated
/// ``` | ||
/// | ||
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usereducer>. | ||
ReducerHook<TState, TActions, TInit> useReducer<TState, TActions, TInit>( |
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.
#nit "Action" should be singular here, so as not to confuse it with flux
ReducerHook<TState, TActions, TInit> useReducer<TState, TActions, TInit>( | |
ReducerHook<TState, TAction, TInit> useReducer<TState, TAction, TInit>( |
Same on the next line and in the below function
+10 |
Motivation
Support useReducer hook in
react-dart
.Changes
ReducerHook
class.useReducer
anduseReducerLazy
functions.Please review: @kealjones-wk @aaronlademann-wf @greglittlefield-wf @joebingham-wk