PluginProbe
Extendify / 1.6.1
Extendify v1.6.1
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / Library / hooks / useModal.js

useModal.js in Extendify 1.6.1, at src/Library/hooks/useModal.js

26 lines 756 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEffect, useState } from '@wordpress/element'
2 import { useGlobalStore } from '@library/state/GlobalState'
3
4 /** Return any pending modals and check if any need to show */
5 export const useModal = () => {
6 const [modal, setModal] = useState(null)
7 const open = useGlobalStore((state) => state.open)
8 const removeAllModals = useGlobalStore((state) => state.removeAllModals)
9
10 // Watches modals added anywhere
11 useEffect(
12 () =>
13 useGlobalStore.subscribe(
14 (state) => state.modals,
15 (value) => setModal(value?.length > 0 ? value[0] : null),
16 ),
17 [],
18 )
19
20 useEffect(() => {
21 if (!open) removeAllModals()
22 }, [open, removeAllModals])
23
24 return modal
25 }
26