This folder documents how to use react-code-view in a Next.js (App Router) project.
pnpm create next-app my-rcv-app --ts --eslint
cd my-rcv-apppnpm add @react-code-view/react @react-code-view/coreIn app/layout.tsx (or pages/_app.tsx for Pages Router):
import '@react-code-view/react/styles/index.css';Create app/rcv-demo/page.tsx:
'use client';
import React from 'react';
import { CodeView } from '@react-code-view/react';
const code = `const Hello = () => <button onClick={() => alert('hi')}>Click</button>;
render(<Hello />);`;
export default function RcvDemoPage() {
return (
<main style={{ padding: 24 }}>
<h1>React Code View in Next.js</h1>
<CodeView
language="tsx"
theme="rcv-theme-default"
renderPreview
showCopyButton
dependencies={{ React }}
>
{code}
</CodeView>
</main>
);
}If you prefer Pages Router, create
pages/rcv-demo.tsxwith the same content (remove'use client';if your project defaults to client components).
pnpm dev
# visit http://localhost:3000/rcv-demo- No extra Next.js config is required; the package ships ESM/CJS builds consumable by Next.
- Ensure the page/component using
CodeViewis a client component ('use client') so hooks can run. - Import the CSS once (in layout or custom App). You can override CSS variables if needed.
- To customize themes, set the
themeprop (e.g.,rcv-theme-dark) and override CSS variables in your global stylesheet.