Understanding Grida's __useInternal() Function In React Canvas
Exploring Grida's __useInternal() function, which provides state and dispatch to child components within a StandaloneDocumentEditor.
In this article, we will review the __useInternal() function in Grida codebase.
function __useInternal() {
const state = useContext(DocumentContext);
if (!state) {
throw new Error(
"useDocument must be used within a StandaloneDocumentEditor"
);
}
const dispatch = __useDispatch();
return useMemo(() => [state, dispatch] as const, [state, dispatch]);
}
How did I come across this function? In the previous articles, I wrote Toolbar component and a function called setCursorMode.
In the useEventTarget function, state and dispatch are destructured fr...