isDocumentVisible

isDocumentVisible() returns true when document.visibilityState is 'visible', reading it fresh on each call. It does not establish a subscription — use it for one-off checks (e.g. inside an event handler) where you don't need reactivity. For reactive forms see useDocumentVisible and onDocumentVisible. Part of pota/use/visibility.

Arguments

This function takes no arguments.

Returns: booleantrue if the document is currently visible.

Examples

One-off check inside a handler

Reads the visibility state once when the button is clicked — no subscription is created, so the value is a snapshot for that moment.

import { render, signal } from 'pota'
import { isDocumentVisible } from 'pota/use/visibility'

function App() {
	const result = signal('')

	return (
		<div>
			<button
				on:click={() =>
					result.write(isDocumentVisible() ? 'visible' : 'hidden')
				}
			>
				check visibility
			</button>
			<p>{result.read}</p>
		</div>
	)
}

render(App)