-
- Notifications
You must be signed in to change notification settings - Fork 155
Closed
Description
In the document/README, it says the type of container returned from useCodeMirror is:
container: HTMLDivElement | null | undefined;However, in the latest version (v4.19.9), the actual type that is exported from the npm package is:
container: HTMLDivElement | undefined;I checked the source code, and I believe the type in document is right.
The source code
// https://github.com/uiwjs/react-codemirror/blob/6968faf74121748c629ab9487d5172beec9de42e/core/src/useCodeMirror.ts#L150 useEffect(() => setContainer(props.container!), [props.container]);- In the first render, the value of
props.containeris actuallynullwhich is the initial value of the refeditorinReactCodeMirror.
This change triggers a second render, because the new valuenullis different from the current valueundefined. - Then in the second render, it can get the
HTMLDivElementand pass it tocontaineragain, triggering a third render. - In the third render, the
containerfinally becomesHTMLDivElement.
During the whole process, the container value is actually undefined -> null -> HTMLDivElement.
Metadata
Metadata
Assignees
Labels
No labels