useException function

ExceptionState useException()

Returns an exception dispatcher.

Implementation

ExceptionState useException() {
  final exception = useState<Exception?>(null);
  final dispatcher = useCallback<void Function(Exception e)>((e) {
    exception.value = e;
  }, const []);

  final getter = useCallback<Exception? Function()>(() {
    return exception.value;
  }, const []);
  final state = useRef(ExceptionState(dispatcher, getter));

  return state.value;
}