Skip to content

Commit

Permalink
Seal ReducerHook, StateHook, and Ref
Browse files Browse the repository at this point in the history
  • Loading branch information
greglittlefield-wf committed Oct 4, 2023
1 parent 086f8cb commit a284dfc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
- markChildrenValidated

#### Other API breakages
- ReducerHook and StateHook have no public constructors and can no longer be extended
- Ref.fromJs is now a factory constructor, meaning the Ref class can no longer be extended
- `ReducerHook`, `StateHook`, and `Ref` are now `@sealed` and may not be inherited from
- ReactComponentFactoryProxy.call and .build return type changed from dynamic to ReactElement
- This matches the type returned from `build` for all subclasses, which is what’s returned by call, and reflects the type returned at runtime
- Has potential to cause some static analysis issues, but for the most part should not affect anything since ReactElement is typically treated as an opaque type
Expand Down
3 changes: 3 additions & 0 deletions lib/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
library hooks;

import 'package:js/js.dart';
import 'package:meta/meta.dart';
import 'package:react/react.dart';
import 'package:react/react_client/react_interop.dart';

Expand All @@ -16,6 +17,7 @@ import 'package:react/react_client/react_interop.dart';
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// Learn more: <https://reactjs.org/docs/hooks-state.html>.
@sealed
class StateHook<T> {
/// The first item of the pair returned by [React.useState].
final T _value;
Expand Down Expand Up @@ -156,6 +158,7 @@ void useEffect(dynamic Function() sideEffect, [List<Object?>? dependencies]) {
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usereducer>.
@sealed
class ReducerHook<TState, TAction, TInit> {
/// The first item of the pair returned by [React.useReducer].
final TState _state;
Expand Down
1 change: 1 addition & 0 deletions lib/react_client/react_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Ref<T?> createRef<T>() => Ref<T?>.fromJs(React.createRef());
/// will be available via [current].
///
/// See [createRef] for usage examples and more info.
@sealed
class Ref<T> {
/// A JavaScript ref object returned by [React.createRef].
final JsRef jsRef;
Expand Down

0 comments on commit a284dfc

Please sign in to comment.