import { useState } from 'react' ; import { Stream } from 'effection' ; import { useOperation } from './use-operation' ; export function useStream < T > ( stream ) ; export function useStream < T > ( stream , initial ) ; export function useStream < T > ( stream , initial ? ) { let [ state , setState ] = useState < T | undefined > ( initial ) ; useOperation ( stream . forEach ( function * ( value ) { setState ( value ) ; } ) , [ stream ] ) ; return state ; }