Skip to content

Commit

Permalink
Remove deprecated StateHook and ReducerHook constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
greglittlefield-wf committed Oct 2, 2023
1 parent c23fffc commit e86096b
Showing 1 changed file with 16 additions and 39 deletions.
55 changes: 16 additions & 39 deletions lib/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ class StateHook<T> {
/// The second item in the pair returned by [React.useState].
final void Function(dynamic) _setValue;

@Deprecated('Use useState instead. Will be removed in 7.0.0.')
factory StateHook(T initialValue) {
final result = React.useState(initialValue);
return StateHook._(result[0] as T, result[1] as void Function(dynamic));
}

/// Constructor for [useStateLazy], calls lazy version of [React.useState] to
/// initialize [_value] to the return value of [init].
///
/// See: <https://reactjs.org/docs/hooks-reference.html#lazy-initial-state>.
@Deprecated('Use useStateLazy instead. Will be removed in 7.0.0.')
factory StateHook.lazy(T Function() init) {
final result = React.useState(allowInterop(init));
return StateHook._(result[0] as T, result[1] as void Function(dynamic));
}

StateHook._(this._value, this._setValue);

/// The current value of the state.
Expand Down Expand Up @@ -79,7 +63,10 @@ class StateHook<T> {
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-state.html>.
StateHook<T> useState<T>(T initialValue) => StateHook(initialValue);
StateHook<T> useState<T>(T initialValue) {
final result = React.useState(initialValue);
return StateHook._(result[0] as T, result[1] as void Function(dynamic));
}

/// Adds local state to a [DartFunctionComponent]
/// by returning a [StateHook] with [StateHook.value] initialized to the return value of [init].
Expand All @@ -102,7 +89,10 @@ StateHook<T> useState<T>(T initialValue) => StateHook(initialValue);
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#lazy-initial-state>.
StateHook<T> useStateLazy<T>(T Function() init) => StateHook.lazy(init);
StateHook<T> useStateLazy<T>(T Function() init) {
final result = React.useState(allowInterop(init));
return StateHook._(result[0] as T, result[1] as void Function(dynamic));
}

/// Runs [sideEffect] after every completed render of a [DartFunctionComponent].
///
Expand Down Expand Up @@ -173,23 +163,6 @@ class ReducerHook<TState, TAction, TInit> {
/// The second item in the pair returned by [React.useReducer].
final void Function(TAction) _dispatch;

@Deprecated('Use useReducer instead. Will be removed in 7.0.0.')
factory ReducerHook(TState Function(TState state, TAction action) reducer, TState initialState) {
final result = React.useReducer(allowInterop(reducer), initialState);
return ReducerHook._(result[0] as TState, result[1] as void Function(TAction));
}

/// Constructor for [useReducerLazy], calls lazy version of [React.useReducer] to
/// initialize [_state] to the return value of [init(initialArg)].
///
/// See: <https://reactjs.org/docs/hooks-reference.html#lazy-initialization>.
@Deprecated('Use useReducerLazy instead. Will be removed in 7.0.0.')
factory ReducerHook.lazy(
TState Function(TState state, TAction action) reducer, TInit initialArg, TState Function(TInit) init) {
final result = React.useReducer(allowInterop(reducer), initialArg, allowInterop(init));
return ReducerHook._(result[0] as TState, result[1] as void Function(TAction));
}

ReducerHook._(this._state, this._dispatch);

/// The current state map of the component.
Expand Down Expand Up @@ -242,8 +215,10 @@ class ReducerHook<TState, TAction, TInit> {
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usereducer>.
ReducerHook<TState, TAction, TInit> useReducer<TState, TAction, TInit>(
TState Function(TState state, TAction action) reducer, TState initialState) =>
ReducerHook(reducer, initialState);
TState Function(TState state, TAction action) reducer, TState initialState) {
final result = React.useReducer(allowInterop(reducer), initialState);
return ReducerHook._(result[0] as TState, result[1] as void Function(TAction));
}

/// Initializes state of a [DartFunctionComponent] to `init(initialArg)` and creates `dispatch` method.
///
Expand Down Expand Up @@ -296,8 +271,10 @@ ReducerHook<TState, TAction, TInit> useReducer<TState, TAction, TInit>(
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#lazy-initialization>.
ReducerHook<TState, TAction, TInit> useReducerLazy<TState, TAction, TInit>(
TState Function(TState state, TAction action) reducer, TInit initialArg, TState Function(TInit) init) =>
ReducerHook.lazy(reducer, initialArg, init);
TState Function(TState state, TAction action) reducer, TInit initialArg, TState Function(TInit) init) {
final result = React.useReducer(allowInterop(reducer), initialArg, allowInterop(init));
return ReducerHook._(result[0] as TState, result[1] as void Function(TAction));
}

/// Returns a memoized version of [callback] that only changes if one of the [dependencies] has changed.
///
Expand Down

0 comments on commit e86096b

Please sign in to comment.