Silind-Software / direflow

🧩 Use the best of two worlds. Create fast, performant, native Web Components using React.
https://direflow.io
MIT License
502 stars 77 forks source link

How to provide component instance methods for external use #282

Open crazyming9528 opened 1 year ago

crazyming9528 commented 1 year ago

I would like to know how to provide component instance methods for external use, thank you

PrimaMateria commented 1 year ago

There is two-way communication between host and web component via web component's properties and events. If this doesn't answer your question, please elaborate more what you want to achieve.

crazyming9528 commented 1 year ago

There is two-way communication between host and web component via web component's properties and events. If this doesn't answer your question, please elaborate more what you want to achieve.

Just like the useImperativeHandle hook in react, can expose the methods of components.

eg.

class MyElement extends HTMLElement {
  ...

  doSomething() {
    // do something in this method
  }

const element = document.querySelector('my-element');
element.doSomething();
crazyming9528 commented 1 year ago

@PrimaMateria Can you help me solve this problem, it is very urgent, thank you very much

PrimaMateria commented 1 year ago

I don't have any knowledge about that, so I am not able to help you.

crazyming9528 commented 1 year ago

I don't have any knowledge about that, so I am not able to help you.

ok,thanks for your reply~

crazyming9528 commented 1 year ago

I use custom event to call a method inside the component