# Fumadocs MDX (the built-in content source): Browser Entry
URL: /docs/mdx/entry/browser
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/mdx/entry/browser.mdx

Access collections from browser/client environment.

<Callout title="Using the Macro API?">
Macro collections can be imported on the client directly, without a client loader. See [Macro API](/docs/mdx/macro#browser) for the equivalent usage.
</Callout>

## Usage [#usage]

The generated outputs are optimized using async imports for browser environments.

Only doc/docs collections are accessible on browser.

```tsx
import browserCollections from 'collections/browser';

// unloaded entries
console.log(browserCollections['collection name'].raw);

// define client-side collection loader
const clientLoader = browserCollections['collection name'].createClientLoader({
  component(
    // access the compiled file
    { default: MDX },
    // define props (optional)
    props: { myProp: string },
  ) {
    return (
      <div>
        <MDX />
      </div>
    );
  },
});

// server (static generator) return a path
async function serverLoader() {
  return source.getPage(slugs)!.path;
}

async function loader() {
  const path = await serverLoader();
  // preload the path
  await clientLoader.preload(path);
  return { path };
}

function Page() {
  const { path } = loader();

  // render the content
  return clientLoader.useContent(path, {
    myProp: 'hello world',
  });
}
```

### Path Params [#path-params]

For a page of [path params](/docs/next/page-conventions#path-params), pass its params after its path:

```tsx
async function serverLoader() {
  const page = source.getPage(slugs)!;
  return { path: page.path, params: page.params };
}

async function loader() {
  const { path, params } = await serverLoader();
  await clientLoader.preload(path, params);
  return { path, params };
}

function Page() {
  const { path, params } = loader();

  return clientLoader.useContent(path, { myProp: 'hello world' }, params);
}
```

## Examples [#examples]

The examples below are for non-RSC usage on React Router and TanStack Start. On Next.js and Waku, prefer RSC with the [server entry](/docs/mdx/entry/server) for better client performance.

The example apps in our repository use the [Macro API](/docs/mdx/macro) for this instead. They are a good reference for a complete setup.

```tsx tab="React Router" title="app/routes/docs.tsx"
import type { Route } from './+types/docs';
import { source } from '@/lib/source';
import browserCollections from 'collections/browser';

export async function loader({ params }: Route.LoaderArgs) {
  const slugs = params['*'].split('/').filter((v) => v.length > 0);
  const page = source.getPage(slugs);
  if (!page) throw new Response('Not found', { status: 404 });

  return {
    path: page.path,
  };
}

const clientLoader = browserCollections.docs.createClientLoader({
  component({ frontmatter, default: MDX }) {
    return (
      <div className="prose">
        <h1>{frontmatter.title}</h1>
        <MDX />
      </div>
    );
  },
});

export default function Page(props: Route.ComponentProps) {
  const { path } = props.loaderData;

  return clientLoader.useContent(path);
}
```

```tsx tab="TanStack Start" title="src/routes/docs/$.tsx"
import { createFileRoute, notFound } from '@tanstack/react-router';
import { createServerFn } from '@tanstack/react-start';
import { source } from '@/lib/source';
import browserCollections from 'collections/browser';

export const Route = createFileRoute('/docs/$')({
  component: Page,
  loader: async ({ params }) => {
    const data = await loader({ data: params._splat?.split('/') ?? [] });
    await clientLoader.preload(data.path);
    return data;
  },
});

const loader = createServerFn({
  method: 'GET',
})
  .validator((slugs: string[]) => slugs)
  .handler(async ({ data: slugs }) => {
    const page = source.getPage(slugs);
    if (!page) throw notFound();

    return {
      path: page.path,
    };
  });

const clientLoader = browserCollections.docs.createClientLoader({
  component({ frontmatter, default: MDX }) {
    return (
      <div className="prose">
        <h1>{frontmatter.title}</h1>
        <MDX />
      </div>
    );
  },
});

function Page() {
  const data = Route.useLoaderData();

  return clientLoader.useContent(data.path);
}
```