craft.js
craft.js copied to clipboard
How to make connections two components
I have two component: A, B How to let the B component know the props update of the A component
you can subscribe the B component to the props update of A component:
function BComponent() {
const { store } = useEditor()
useEffect(() => {
const unsubscribe = store.subscribe(
state => {
return {
// you have to get the id of A component
props: state.nodes[idOfAComponent].data.props
}
},
collected => {
console.log(collected.props);
}
)
return () => unsubscribe();
}, [store])
// ...
}
How to get A component id?can i set the id?
How to get A component id?can i set the id?
You can store the A component's id inside the B components' props
or custom
object considering the A component has already been created when you are creating the B component.