useNow

Reactive dark theme preference.

Related hooks

Inspired on:

Visual example

site title
domain.tld
Fri Apr 17 2026 10:03:06 GMT+0000 (Coordinated Universal Time)

Code base

import type { Writable } from "svelte/store";
import { writable } from "svelte/store";

import { useIntervalFn } from "@/hooks/useIntervalFn";

export function useNow(): Writable<Date> {
	const now = writable(new Date());

	const update = () => { now.set(new Date()) }

	useIntervalFn(update, 1000, { immediate: true });

	return now;
}

Code example

<!-- javascript -->
<script lang="ts">
	import { useNow } from "@dimaslz/svelteuse";

	const now = useNow();
</script>

<!-- html -->
<div>
	<pre>{$now}</pre>
</div>