Skip to content

Commit

Permalink
non null ftw
Browse files Browse the repository at this point in the history
  • Loading branch information
coolov committed Jan 26, 2024
1 parent 0d351ae commit 987fd37
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ Note that components that use this hook must be descendants of the
### `useEditorState`

```tsx
type useEditorState = () => EditorState | null;
type useEditorState = () => EditorState;
```

Provides access to the current EditorState value.
Expand Down
4 changes: 3 additions & 1 deletion src/components/ProseMirrorInner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export function ProseMirrorInner({
});

const editorState =
"state" in editorProps ? editorProps.state : editorView?.state ?? null;
"defaultState" in editorProps
? editorProps.defaultState
: editorProps.state;

const editorContextValue = useMemo(
() => ({
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/EditorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { EventHandler } from "../plugins/componentEventListeners";

interface EditorContextValue {
editorView: EditorView | null;
editorState: EditorState | null;
editorState: EditorState;
registerEventListener<EventType extends keyof DOMEventMap>(
eventType: EventType,
handler: EventHandler<EventType>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useEditorState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EditorContext } from "../contexts/EditorContext.js";
/**
* Provides access to the current EditorState value.
*/
export function useEditorState(): EditorState | null {
export function useEditorState(): EditorState {
const { editorState } = useContext(EditorContext);

return editorState;
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useNodePos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const NodePosContext = createContext<number>(null as unknown as number);

export function NodePosProvider({ nodeKey, children }: Props) {
const editorState = useEditorState();
if (!editorState) return <>{children}</>;
const pluginState = reactPluginKey.getState(editorState);
if (!pluginState) return <>{children}</>;
return (
Expand Down

0 comments on commit 987fd37

Please sign in to comment.