-
-
Notifications
You must be signed in to change notification settings - Fork 150
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.container
is actuallynull
which is the initial value of the refeditor
inReactCodeMirror
.
This change triggers a second render, because the new valuenull
is different from the current valueundefined
. - Then in the second render, it can get the
HTMLDivElement
and pass it tocontainer
again, triggering a third render. - In the third render, the
container
finally becomesHTMLDivElement
.
During the whole process, the container
value is actually undefined
-> null
-> HTMLDivElement
.
Metadata
Metadata
Assignees
Labels
No labels