--- title: browser --- `browser` lets you mark a component as browser-only during server rendering. ```js use(browser(reason?)) ``` --- ## Reference {/*reference*/} ### `browser(reason?)` {/*browser*/} Call `browser` inside [`use`](/reference/react/use) to mark a component as browser-only during server rendering: ```js import { use } from 'react'; import { browser } from 'react-dom'; function BrowserOnly() { use(browser('This component requires browser APIs.')); return ; } ``` During server rendering, `use(browser())` stops rendering the component and leaves the closest [``](/reference/react/Suspense) boundary's fallback in its place. In the browser, `use(browser())` returns `undefined`, so the component renders normally. [See more examples below.](#usage) #### Parameters {/*parameters*/} * **optional** `reason`: A string or function that explains why the content needs to render in the browser. The string or the function's return value becomes the `cause` of the `Error` passed to [`onBrowserBailout`](#reporting-browser-only-rendering-on-the-server). React calls a reason function each time a server renderer encounters the value returned by `browser`, but does not call it in the browser. If creating the reason is expensive, pass a function such as `() => new Error(...)`. #### Returns {/*returns*/} `browser` returns an opaque value that you can pass to `use` in a component or use as the reason when [aborting a server render](#aborting-pending-server-rendering-for-the-browser). In the browser, passing this value to `use` returns `undefined`. #### Caveats {/*caveats*/} * `use(browser())` must be inside a `` boundary during server rendering. Without one, the server render fails. * `use(browser())` must be called from a [Client Component](/reference/rsc/use-client), not a [Server Component](/reference/rsc/server-components). * Calling `browser()` by itself has no effect. To mark a component as browser-only, pass the value returned by `browser` to `use`. Do not throw it. --- ## Usage {/*usage*/} ### Rendering content only in the browser {/*rendering-content-only-in-the-browser*/} Call `browser` inside `use` in a component that should only render in the browser: You can use this instead of checking `typeof window`, waiting for an [`Effect`](/reference/react/useEffect) to set mounted state, or using a framework option to disable server rendering. Click **Reload** to see the loading fallback in the initial HTML. After hydration, React displays the draft loaded from `localStorage`. ```js src/App.js active import { Suspense, use, useState } from 'react'; import { browser } from 'react-dom'; function SavedDraft() { use(browser('The draft is stored in localStorage.')); const [draft, setDraft] = useState( () => localStorage.getItem('draft') ?? '' ); function handleChange(event) { const nextDraft = event.target.value; setDraft(nextDraft); localStorage.setItem('draft', nextDraft); } return (