craft.js icon indicating copy to clipboard operation
craft.js copied to clipboard

What is the difference between `setProp` in `useNode` and `useEditor` hooks?

Open emewjin opened this issue 1 year ago • 1 comments

The useNode and useEditor hooks both provide the actions.setProp. The documentation provides descriptions for each method as shown below, but I'm not entirely clear on the differences.
What is the difference between setProp in useNode and useEditor hooks? The way they are used may vary slightly, but their ultimate function is the same?

const {
    // Docs: Manipulate the props of the given Node. 
    // type: (nodeId: NodeId, update: (props: Object) => void) => void
    actions: { setProp },
  } = useEditor();

const {
    // Docs: Manipulate the current component's props. Additionally, specify a throttleRate to throttle the changes recoded in history for undo/redo
    // type: (props: Object, throttleRate?: number) => void
    actions: { setProp },
  } = useNode();

emewjin avatar Nov 02 '23 23:11 emewjin

Only thing is setProp from Editor accepts an ID so you can change any prop of any node. The other one is node's setProp function. You can only change current node's props

brerdem avatar Dec 14 '23 09:12 brerdem