tweak-tools
Version:
Tweak your React projects until awesomeness
19 lines (15 loc) • 529 B
text/typescript
import { useState, useEffect } from 'react'
import shallow from 'zustand/shallow'
import type { StoreType } from '../types'
/**
* Hook used by the root component to get all visible inputs.
*/
export const useVisiblePaths = (store: StoreType) => {
const [paths, setPaths] = useState(store.getVisiblePaths())
useEffect(() => {
setPaths(store.getVisiblePaths())
const unsub = store.useStore.subscribe(store.getVisiblePaths, setPaths, { equalityFn: shallow })
return () => unsub()
}, [store])
return paths
}