({
sections,
children
}: {
sections: Array<Section>;
children: React.ReactNode;
})
| 129 | typeof window === 'undefined' ? useEffect : useLayoutEffect; |
| 130 | |
| 131 | export function SectionProvider({ |
| 132 | sections, |
| 133 | children |
| 134 | }: { |
| 135 | sections: Array<Section>; |
| 136 | children: React.ReactNode; |
| 137 | }) { |
| 138 | let [sectionStore] = useState(() => createSectionStore(sections)); |
| 139 | |
| 140 | useVisibleSections(sectionStore); |
| 141 | |
| 142 | useIsomorphicLayoutEffect(() => { |
| 143 | sectionStore.setState({ sections }); |
| 144 | }, [sectionStore, sections]); |
| 145 | |
| 146 | return ( |
| 147 | <SectionStoreContext.Provider value={sectionStore}> |
| 148 | {children} |
| 149 | </SectionStoreContext.Provider> |
| 150 | ); |
| 151 | } |
| 152 | |
| 153 | export function useSectionStore<T>(selector: (state: SectionState) => T) { |
| 154 | let store = useContext(SectionStoreContext); |
nothing calls this directly
no test coverage detected