import { Button } from '@material-ui/core'; import React from 'react'; import { Bloc } from '../../lib'; import { useBloc } from '../state'; const wait = (): Promise => { return new Promise((resolve) => { setTimeout(() => { resolve(-1); }, 1500); }); } class CounterEvent {} class CounterIncrementPressed extends CounterEvent {} class LazyBloc extends Bloc { constructor() { super(0); this.on(CounterIncrementPressed, async (event, emit) => { emit(this.state + 1); const add = await wait(); emit(this.state + add); }); } } const LazyToggle = () => { const [state, bloc] = useBloc(LazyBloc, { create: () => new LazyBloc(), }); return ; }; export default LazyToggle;