-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |