---
url: /reference/items/Fetch.md
---
# Fetch
The `Fetch` component adds AJAX capabilities to your existing HTML, with support for the [View Transition API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API) to transition between states.
## Usage
The `Fetch` component can be used to perform GET or POST requests without reloading the page.
```js twoslash
import { registerComponent } from '@studiometa/js-toolkit';
import { Fetch } from '@studiometa/ui';
registerComponent(Fetch);
```
### Basic
Given the following HTML:
```html
Click me
```
And the following response from the `/some-content` endpoint:
```html
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Some extra content.
```
Clicking on the link will dispatch a background fetch request and will replace the `` element with the new content from the fetch response. The page will have the following HTML after:
```html
Click me
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
```
::: warning 💡 Important
We use `id` attributes to detect which content from the response should be used and injected in the DOM. Any content from the response not nested in a parent with an `id` attribute will be discarded.
:::
### From any element
The `Fetch` component is not limited to `` and `
...
```
```json [/api/msg]
{
"rendered": "Hello world!
"
}
```
```ts [app.ts] twoslash
import { registerComponent } from '@studiometa/js-toolkit';
import { Fetch } from '@studiometa/ui';
registerComponent(Fetch);
```
:::