Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jill64 committed Dec 13, 2023
1 parent d519642 commit a247813
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
# svelte-hydrated
💧 Indicating hydration status by svelte-store
<!----- BEGIN GHOST DOCS HEADER ----->
<!----- END GHOST DOCS HEADER ----->

## Installation

```bash
npm i svelte-hydrated
```

## Example

The `$hydrated` store is updated to `true` at the next tick when the `browser` is `true`

```svelte
<script>
import { hydrated } from 'svelte-hydrated'
import { slide } from 'svelte/transition'
</script>
{#if $hydrated}
<h2 transition:slide>Hydrated</h2>
{:else}
<h2 transition:slide>Not Hydrated</h2>
{/if}
```

## Why not use `browser` ?

The `browser` (`$app/environment`) is useful for identifying the execution environment of the code, but its value is determined before the first rendering is started.
This means that `transition` etc. will not be triggered when hydration completes.
The `$hydrated` store is updated to `true` at the next `tick` when the browser is `true`, making it simpler to set `transition`.

0 comments on commit a247813

Please sign in to comment.