Download slate/packages/slate-react/src/hooks/use-element.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 556 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/slate/packages/slate-react/src/hooks/use-element.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/slate/packages/slate-react/src/hooks/use-element.ts
-
curl -L -o use-element.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/slate/packages/slate-react/src/hooks/use-element.ts
556 Bytes
| import { createContext, useContext } from 'react' | |
| import { Element } from 'slate' | |
| export const ElementContext = createContext<Element | null>(null) | |
| /** | |
| * Get the current element. | |
| */ | |
| export const useElement = (): Element => { | |
| const context = useContext(ElementContext) | |
| if (!context) { | |
| throw new Error( | |
| 'The `useElement` hook must be used inside `renderElement`.' | |
| ) | |
| } | |
| return context | |
| } | |
| /** | |
| * Get the current element, or return null if not inside `renderElement`. | |
| */ | |
| export const useElementIf = () => useContext(ElementContext) | |