import { useState } from 'react' ; import { Stream } from 'effection' ; import { useOperation } from './use-operation' ; interface Slice < T > extends Stream < T > { get ( ) : T ; } export function useSlice < T > ( slice ) { let [ state , setState ] = useState < T > ( slice . get ( ) ) ; useOperation ( slice . forEach ( function * ( value ) { setState ( value ) ; } ) , [ slice ] ) ; return state ; }