Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make connections two components #593

Closed
xushichen opened this issue Dec 21, 2023 · 3 comments
Closed

How to make connections two components #593

xushichen opened this issue Dec 21, 2023 · 3 comments

Comments

@xushichen
Copy link

I have two component: A, B
How to let the B component know the props update of the A component

@rohailtaha
Copy link

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])
  
  // ...
}

@xushichen
Copy link
Author

How to get A component id?can i set the id?

@rohailtaha
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants