# extendify/0.11.0/src/Assist/state/Global.js

Extendify, version 0.11.0. 47 lines.

- Page: https://pluginprobe.com/plugins/extendify/0.11.0/code/src/Assist/state/Global.js
- Raw: https://pluginprobe.com/plugins/extendify/0.11.0/raw/src/Assist/state/Global.js
- Modified: 2022-10-07T04:54:12+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/extendify/0.11.0/code/src/Assist/state/Global.js#L10-L20`.

```javascript
import { useEffect, useState } from '@wordpress/element'
import create from 'zustand'
import { devtools, persist } from 'zustand/middleware'
import { getGlobalData, saveGlobalData } from '../api/Data'

const state = (set, get) => ({
    dismissedNotices: [],
    isDismissed(id) {
        return get().dismissedNotices.some((notice) => notice.id === id)
    },
    dismissNotice(id) {
        if (get().isDismissed(id)) return
        const notice = { id, dismissedAt: new Date().toISOString() }
        set((state) => ({
            dismissedNotices: [...state.dismissedNotices, notice],
        }))
    },
})

const storage = {
    getItem: async () => JSON.stringify(await getGlobalData()),
    setItem: async (_, value) => await saveGlobalData(value),
    removeItem: () => undefined,
}

export const useGlobalStore = create(
    persist(devtools(state, { name: 'Extendify Assist Globals' }), {
        name: 'extendify-assist-globals',
        getStorage: () => storage,
    }),
    state,
)

/* Hook useful for when you need to wait on the async state to hydrate */
export const useGlobalStoreReady = () => {
    const [hydrated, setHydrated] = useState(useGlobalStore.persist.hasHydrated)
    useEffect(() => {
        const unsubFinishHydration = useGlobalStore.persist.onFinishHydration(
            () => setHydrated(true),
        )
        return () => {
            unsubFinishHydration()
        }
    }, [])
    return hydrated
}

```
