From 05df4e806a46581d7be527ea6c8bee8386366404 Mon Sep 17 00:00:00 2001 From: Prev Wong Date: Fri, 17 Jan 2020 11:30:44 +0800 Subject: [PATCH 1/2] fix docs start command --- packages/docs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docs/package.json b/packages/docs/package.json index fec024c38..fe43fd04a 100755 --- a/packages/docs/package.json +++ b/packages/docs/package.json @@ -3,7 +3,7 @@ "version": "0.1.0-beta.1", "private": true, "scripts": { - "start-docs": "docusaurus start", + "start": "docusaurus start", "build": "docusaurus build", "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy" From cf01dce6c59a571a2feba66b5b5d8c12b74a1418 Mon Sep 17 00:00:00 2001 From: Prev Wong Date: Fri, 17 Jan 2020 11:34:41 +0800 Subject: [PATCH 2/2] (#19) fix typo, added example for setProp --- packages/docs/docs/api/useEditor.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/docs/docs/api/useEditor.md b/packages/docs/docs/api/useEditor.md index 609c612af..1e6d7aebb 100644 --- a/packages/docs/docs/api/useEditor.md +++ b/packages/docs/docs/api/useEditor.md @@ -39,7 +39,7 @@ const { connectors, actions, query, ...collected } = useEditor(collector); ["delete", "(nodeID: NodeId) => void", "Delete the specified Node"], ["deserialize", "() => String", "Recreate Nodes from JSON. This will clear all the current Nodes in the editor state with the recreated Nodes"], ["move", "(nodeId: NodeId, targetParentId: NodeId, index: number) => void", "Move a Node to the specified parent Node at the given index."], - ["setProp", "(nodeId: NodeId, props: Object) => void", "Manipulate the props of the given Node"], + ["setProp", "(nodeId: NodeId, update: (props: Object) => void) => void", "Manipulate the props of the given Node"], ["setHidden", "(nodeId: NodeId, bool: boolean) => void", "When set to true, the User Component of the specified Node will be hidden, but not removed"], ["setCustom", "(nodeId: NodeId, custom: (custom: Object) => void", "Update the given Node's custom properties"], ["setOptions", "(options: Object) => void", "Update the editor's options. The options object passed is the same as the <Editor /> props."] @@ -79,6 +79,29 @@ const Example = () => { } ``` +### Updating props +```tsx +import {useEditor} from "@craftjs/core"; + +const Example = () => { + const { selectedNodeId, actions: {setProp} } = useEditor((state) => ({ + selectedNodeId: state.events.selected + })); + + return ( + { + setProp(selectedNodeId, props => { + props.text = "new value"; + }); + }} + > + Update + + ) +} +``` + ### Hiding and Deleting a Node ```jsx const Example = () => {