Skip to content

Commit

Permalink
NodePosProvider key -> nodeKey (#63)
Browse files Browse the repository at this point in the history
Fixes react warning when using key prop
  • Loading branch information
saranrapjs authored Nov 14, 2023
1 parent b4dbdeb commit 08baec4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .yarn/versions/5245b9ba.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releases:
"@nytimes/react-prosemirror": patch
6 changes: 3 additions & 3 deletions src/hooks/useNodePos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import { NodeKey, reactPluginKey } from "../plugins/react.js";
import { useEditorState } from "./useEditorState.js";

type Props = {
key: NodeKey;
nodeKey: NodeKey;
children: ReactNode;
};

const NodePosContext = createContext<number>(null as unknown as number);

export function NodePosProvider({ key, children }: Props) {
export function NodePosProvider({ nodeKey, children }: Props) {
const editorState = useEditorState();
if (!editorState) return <>{children}</>;
const pluginState = reactPluginKey.getState(editorState);
return (
<NodePosContext.Provider value={pluginState?.keyToPos.get(key) ?? 0}>
<NodePosContext.Provider value={pluginState?.keyToPos.get(nodeKey) ?? 0}>
{children}
</NodePosContext.Provider>
);
Expand Down
2 changes: 1 addition & 1 deletion src/nodeViews/createReactNodeViewConstructor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export function createReactNodeViewConstructor(
[node, contentDOMWrapper, contentDOMParent]
);
return (
<NodePosProvider key={nodeKey}>
<NodePosProvider nodeKey={nodeKey}>
<ReactComponent
node={node}
decorations={decorations}
Expand Down

0 comments on commit 08baec4

Please sign in to comment.