> For the complete documentation index, see [llms.txt](https://atomico.gitbook.io/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://atomico.gitbook.io/doc/guides/atomico-design-patterns/webcomponents-with-hybrid-rendering.md).

# Webcomponents with hybrid rendering

Normally we create webcomponents that only work with lightDOM or shadowDOM, example:

```jsx
function componentWithLightDom() {
  return (
    <host>
      <h1>I am in the lightDOM</h1>
    </host>
  );
}

function componentWithShadowDom() {
  return (
    <host shadowDom>
      <h1>I am inside the shadowDOM</h1>
    </host>
  );
}
```

With atomico you can go further thanks to the hook [`@atomico/hooks/use-render`](/doc/packages/atomico-hooks/use-render.md) which allows you to execute renders independent of the main one, example:

```jsx
import { useRender } from "@atomico/hooks/use-render";

function componentWithLightDomAndShadowDom() {
  useRender(() => <h1>I am in the lightDOM</h1>);
  return (
    <host shadowDom>
      <h1>I am inside the shadowDOM</h1>
    </host>
  );
}
```

### What are the benefits of using useRender?

1. Encapsulate DOM fragments within custom Hooks and then render to any webcomponent.
2. patch the limitations of webcomponents that use shadowDOM, to improve communication with forms.

### Patch the limitations of web components that use shadow DOM, to improve communication with forms

```jsx
import { css, useProp } from "atomico";
import { useRender } from "@atomico/hooks/use-render";

function componentWithLightDomAndShadowDom(props) {
  const [value, setValue] = useProp("value");

  useRender(() => (
    <input {...props} oninput={({ target }) => setValue(target.value)} />
  ));

  return (
    <host shadowDom>
      <slot />
    </host>
  );
}

componentWithLightDomAndShadowDom.props = {
  type: {
    type: String,
    reflect: true,
    value: "text",
  },
  value: String,
};

componentWithLightDomAndShadowDom.styles = css`
  ::slotted([type="text"]) {
    border: 1px solid black;
  }
  ::slotted([type="checked"]) {
    width: 30px;
    height: 30px;
    border: 1px solid black;
  }
`;
```

With the `useRender(...)` fragment we are managing to render an input in the lightDOM, thanks to this we will be able to control said input from inside the webcomponent.

### Conclucion

Thanks to useRender you will be able to work together with LightDOM and shadowDOM from the scope of the webcomponent created with Atomico.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://atomico.gitbook.io/doc/guides/atomico-design-patterns/webcomponents-with-hybrid-rendering.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
