# use-channel

Now, Atomico includes a context API as part of its core. We recommend implementing it as an alternative to using `useChannel`.

{% content-ref url="/pages/8kW030mxIe5DZX6irP3V" %}
[useContext](/doc/api/hooks/usecontext.md)
{% endcontent-ref %}

\
An alternative to React's context but solely based on hooks.

### Modulo

```javascript
import { useChannel } from "@atomico/hooks/use-channel";
```

### Syntax

```javascript
const channel = "MyChannel";
const [parentValue, setChildValue] = useChannel(channel);
```

Where :

1. `channel`: `String`, defines the name of the event to be used to generate the channel.
2. `parentValue`: Value inherited by the parent component.
3. `setChildValue`: `Callback`, defines a value for nested components.

### Example

{% embed url="<https://webcomponents.dev/edit/collection/n2tZyzx4LMKqk1jNE0e9/34DlYUfeqmk0sO3BUa31/src/index.jsx>" %}

This hook is used by [@atomico/components/router](/doc/packages/atomico-components/keen-slider.md)


---

# Agent Instructions: 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:

```
GET https://atomico.gitbook.io/doc/packages/atomico-hooks/use-channel.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
