Skip to content

Commit 1a0c3d8

Browse files
authored
WEB-101 Use selectors with createUsePuck (#104)
Avoids unnecessary rerenders on other properties
2 parents 0aa8b65 + 895c830 commit 1a0c3d8

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/app/editor/[id]/ActionBarOverride.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"use client";
22

33
import { useCallback, useRef } from "react";
4-
import { ActionBar, usePuck } from "@puckeditor/core";
4+
import { ActionBar, createUsePuck } from "@puckeditor/core";
55
import type { ComponentData, Config } from "@puckeditor/core";
66
import { Copy, CopyPlus, ClipboardPaste } from "lucide-react";
77

8+
const usePuck = createUsePuck();
9+
810
const CLIPBOARD_MARKER = "_puckClipboard";
911

1012
type ClipboardPayload = {
@@ -92,7 +94,10 @@ export function ActionBarOverride({
9294
label?: string;
9395
parentAction: React.ReactNode;
9496
}) {
95-
const { selectedItem, config, dispatch, getSelectorForId } = usePuck();
97+
const selectedItem = usePuck((s) => s.selectedItem);
98+
const config = usePuck((s) => s.config);
99+
const dispatch = usePuck((s) => s.dispatch);
100+
const getSelectorForId = usePuck((s) => s.getSelectorForId);
96101
const isPastingRef = useRef(false);
97102

98103
const handleDuplicate = useCallback(() => {

0 commit comments

Comments
 (0)