UNPKG

@atlaskit/dropdown-menu

Version:

A dropdown menu displays a list of actions or options to a user.

37 lines 1.1 kB
import React, { useMemo, useRef } from 'react'; import { SelectionStoreContext } from './selection-store-context'; /** * Selection store will persist data as long as it remains mounted. * It handles the uncontrolled story for dropdown menu when the menu * items can be mounted/unmounted depending if the menu is open or closed. */ const SelectionStore = props => { const { children } = props; const store = useRef({}); const context = useMemo(() => ({ setItemState: (group, id, value) => { if (!store.current[group]) { store.current[group] = {}; } store.current[group][id] = value; }, getItemState: (group, id) => { if (!store.current[group]) { return undefined; } return store.current[group][id]; }, setGroupState: (group, value) => { store.current[group] = value; }, getGroupState: group => { return store.current[group] || {}; } }), []); return /*#__PURE__*/React.createElement(SelectionStoreContext.Provider, { value: context }, children); }; export default SelectionStore;