craft.js
craft.js copied to clipboard
What is the difference between `setProp` in `useNode` and `useEditor` hooks?
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();
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