import React , { useContext , useEffect , useLayoutEffect } from 'react' ; import { environment } from '../../environment' ; import { Store } from '../Store' ; param feature export const useFeature = ( feature , isIsomorphic = false ) => { if ( isIsomorphic ) { feature . store . start ( ) ; } else if ( environment . IS_CLIENT ) { useLayoutEffect ( ( ) => { feature . store . start ( ) ; } , [ ] ) ; } if ( environment . IS_SERVER ) { return ; } useEffect ( ( ) => { return ( ) => { feature . store . stop ( ) ; } ; } , [ ] ) ; } ; param context export function ensureContextExists < T > ( context ) { const instance = useContext ( context ) ; if ( ! instance ) { throw new Error ( `You need to provide a context before using it.` ) ; } return instance ; }