Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ubermanu/arrosoir

🚿 Hydrate HTML with a selector and a url
https://github.com/ubermanu/arrosoir

dom html hydration

Last synced: about 2 months ago
JSON representation

🚿 Hydrate HTML with a selector and a url

Awesome Lists containing this project

README

        

# Arrosoir

[![CI](https://github.com/ubermanu/arrosoir/actions/workflows/ci.yml/badge.svg)](https://github.com/ubermanu/arrosoir/actions/workflows/ci.yml)

Small DOM hydration function for generated HTML.

### Install

npm install arrosoir

### Usage

```js
import { hydrate } from 'arrosoir'
await hydrate(selector, url)
```

For example:

```html

import { hydrate } from 'https://cdn.skypack.dev/arrosoir'

const url = new URL(location.href)
let p = url.searchParams.get('p') * 1 || 1

document.querySelector('button.load-more').addEventListener('click', async () => {
url.searchParams.set('p', ++p)
await hydrate('ul.list', url.toString(), { merge: 'append' })
})

```

> The previous example fetches the page with a different query string.

> The `hydrate` function will merge the new HTML into the existing DOM.

### Options

- `merge`: Append the new HTML to the selector.
- `history`: Replace the current URL with the fetched one.