UNPKG

@bloc-js/react-bloc

Version:

React components for implementing the BLoC pattern.

25 lines (24 loc) 722 B
import { Component, createElement } from "react"; export function withBlocs(creator) { return function injectBlocProps(Comp) { return class WithBlocsHOC extends Component { constructor(props) { super(props); this.blocs = creator(props); } blocs; componentWillUnmount() { for (const key in this.blocs) { const bloc = this.blocs[key]; bloc.complete(); } } render() { return createElement(Comp, { ...this.props, ...this.blocs, }); } }; }; }