resizeObserverStore

Easy way to create ResizeObservers.

Demo

Resize the box to see changes

Usage

<script lang="ts">
import { resizeObserverStore } from "svelte-legos";

let ref: HTMLElement | null = null;

let width = 0;
let height = 0;

function handler([entry]: ResizeObserverEntry[]) {
  width = entry.contentRect.width;
  height = entry.contentRect.height;
}

$: ref && resizeObserverStore(ref, handler);

// use width and height
</script>