@bloc-js/react-bloc
Advanced tools
Comparing version
import { Bloc } from "@bloc-js/bloc"; | ||
export declare function useBlocState<S>(bloc: Bloc<any, S>): S; | ||
export declare type CreateBlocFn<S> = () => Bloc<any, S>; | ||
export declare function useBlocState<S>(bloc: Bloc<any, S> | CreateBlocFn<S>): S | undefined; |
import { useEffect, useState } from "react"; | ||
export function useBlocState(bloc) { | ||
var _a = useState(bloc.currentState), state = _a[0], setState = _a[1]; | ||
var _a = useState(), state = _a[0], setState = _a[1]; | ||
useEffect(function () { | ||
var subscription = bloc.state$.subscribe(function (nextState) { | ||
var actualBloc = typeof bloc === "function" ? bloc() : bloc; | ||
setState(actualBloc.currentState); | ||
var subscription = actualBloc.state$.subscribe(function (nextState) { | ||
setState(nextState); | ||
}); | ||
return function () { return subscription.unsubscribe(); }; | ||
}); | ||
}, []); | ||
return state; | ||
} | ||
//# sourceMappingURL=use-bloc-state.js.map |
import { Bloc } from "@bloc-js/bloc"; | ||
export declare function useBlocState<S>(bloc: Bloc<any, S>): S; | ||
export declare type CreateBlocFn<S> = () => Bloc<any, S>; | ||
export declare function useBlocState<S>(bloc: Bloc<any, S> | CreateBlocFn<S>): S | undefined; |
import { useEffect, useState } from "react"; | ||
export function useBlocState(bloc) { | ||
const [state, setState] = useState(bloc.currentState); | ||
const [state, setState] = useState(); | ||
useEffect(() => { | ||
const subscription = bloc.state$.subscribe(nextState => { | ||
const actualBloc = typeof bloc === "function" ? bloc() : bloc; | ||
setState(actualBloc.currentState); | ||
const subscription = actualBloc.state$.subscribe(nextState => { | ||
setState(nextState); | ||
}); | ||
return () => subscription.unsubscribe(); | ||
}); | ||
}, []); | ||
return state; | ||
} | ||
//# sourceMappingURL=use-bloc-state.js.map |
import { Bloc } from "@bloc-js/bloc"; | ||
export declare function useBlocState<S>(bloc: Bloc<any, S>): S; | ||
export declare type CreateBlocFn<S> = () => Bloc<any, S>; | ||
export declare function useBlocState<S>(bloc: Bloc<any, S> | CreateBlocFn<S>): S | undefined; |
@@ -5,9 +5,11 @@ "use strict"; | ||
function useBlocState(bloc) { | ||
var _a = react_1.useState(bloc.currentState), state = _a[0], setState = _a[1]; | ||
var _a = react_1.useState(), state = _a[0], setState = _a[1]; | ||
react_1.useEffect(function () { | ||
var subscription = bloc.state$.subscribe(function (nextState) { | ||
var actualBloc = typeof bloc === "function" ? bloc() : bloc; | ||
setState(actualBloc.currentState); | ||
var subscription = actualBloc.state$.subscribe(function (nextState) { | ||
setState(nextState); | ||
}); | ||
return function () { return subscription.unsubscribe(); }; | ||
}); | ||
}, []); | ||
return state; | ||
@@ -14,0 +16,0 @@ } |
{ | ||
"name": "@bloc-js/react-bloc", | ||
"version": "1.2.17", | ||
"version": "1.2.18", | ||
"description": "React components for implementing the BLoC pattern.", | ||
@@ -47,3 +47,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "f5dd68795f715516e9787630cb8b35b470a92a6f" | ||
"gitHead": "672226bcf8d9441652523c6fed641f7b67775281" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
11172
9.68%125
7.76%