Detect if your Astro island is running in the browser, or on the server.
@otterlord/is-land
is most useful on Astro islands hydrated using client:load
.
---
import MyIsland from '~/components/MyIsland.tsx'
---
<MyIsland client:load>
Import the @otterlord/is-land
package, and call it to check if your running in the browser.
import { h } from 'preact'
import isLand from '@otterlord/is-land'
export default function MyIsland() {
if (isLand()) alert('Hello browser!')
return (
<h1>Hello world!</h1>
);
}