MCPcopy Create free account
hub / github.com/SyntaxUI/syntaxui / createSectionStore

Function createSectionStore

src/components/SectionProvider.tsx:37–63  ·  view source on GitHub ↗
(sections: Array<Section>)

Source from the content-addressed store, hash-verified

35}
36
37function createSectionStore(sections: Array<Section>) {
38 return createStore<SectionState>()((set) => ({
39 sections,
40 visibleSections: [],
41 setVisibleSections: (visibleSections) =>
42 set((state) =>
43 state.visibleSections.join() === visibleSections.join()
44 ? {}
45 : { visibleSections },
46 ),
47 registerHeading: ({ id, ref, offsetRem }) =>
48 set((state) => {
49 return {
50 sections: state.sections.map((section) => {
51 if (section.id === id) {
52 return {
53 ...section,
54 headingRef: ref,
55 offsetRem,
56 }
57 }
58 return section
59 }),
60 }
61 }),
62 }))
63}
64
65function useVisibleSections(sectionStore: StoreApi<SectionState>) {
66 let setVisibleSections = useStore(sectionStore, (s) => s.setVisibleSections)

Callers 1

SectionProviderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected