import { randomId } from 'lib/id' import { useCallback, useReducer, useState } from 'preact/hooks' export const useForceUpdate = () => { // This is an escape hatch mentioned in the React docs: // https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate const [_, forceUpdate] = useReducer((x) => x + 1, 0) return useCallback(() => { setTimeout(() => { // @ts-ignore forceUpdate() }) }, []) } export const useGeneratedId = () => { const [id] = useState(() => randomId()) return id }