hooks.ts 484 B

12345678910111213141516
  1. import { useContext } from 'react'
  2. import { useStore } from 'zustand'
  3. import { FeaturesContext } from './context'
  4. import type { FeatureStoreState } from './store'
  5. export function useFeatures<T>(selector: (state: FeatureStoreState) => T): T {
  6. const store = useContext(FeaturesContext)
  7. if (!store)
  8. throw new Error('Missing FeaturesContext.Provider in the tree')
  9. return useStore(store, selector)
  10. }
  11. export function useFeaturesStore() {
  12. return useContext(FeaturesContext)
  13. }