0

I have created one search component using stencil and I'm integrating this stencil codebase with my react application via cdn link. I'm displaying the search component(which was created in stencil) as below in my react codebase :

<custom-search placeholder="Search"></custom-search>

The search component contains a search icon. I need to pass the text in search input field to my react code on click of this icon. How can this be achieved?

sneha
  • 11
  • 2
  • If you want to talk between components you can check [this](https://stackoverflow.com/a/55027467/13464279) link. – J.F. Aug 02 '21 at 09:36

2 Answers2

0

Unfortunately I haven't integrate Stencil JS component with React, but passing string data to web component should be working without too much hassle. Do you know if your React app can properly recognize your custom-search component? If not, then you might want to take a look at a link to Stencil JS official document of integrating Stencil JS component to React and make sure component get properly loaded and integrated.

If you know for sure you load the component then not sure why your placeholder is not set within your component - it is just a string after all. Maybe post the custom-search component code, as there might be issue with that (i.e. component lifecycle event you are using might not be doing what you expect to do)

tomokat
  • 142
  • 1
  • 8
0

Could you clarify the actual problem, please? :)

Does the component not get rendered, or are you unable to achieve communication from custom-search to the React app?

If the latter is the case, you might want to implement a Custom Event on the Stencil component, to communicate changes back to the consuming app.

As @tomokat mentioned, you should follow the official Stencil React integration docs. This is required, since React cannot handle Custom Events natively, and requires some help from the dev.

Edit: Sorry, I got confused by the first answer. Your title is quite clear, though. If you can show some example code of the component and the React integration, we could probably help in a better way.