npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@react-code-view/react

v3.1.0

Published

React components for rendering code with live preview

Readme

@react-code-view/react

React components for rendering code with live preview and syntax highlighting.

Installation

pnpm add @react-code-view/react @react-code-view/core
# or
npm install @react-code-view/react @react-code-view/core

Quick Start

import { CodeView } from '@react-code-view/react';
import '@react-code-view/react/styles/index.css';

function App() {
  const code = `
<Button color="primary">
  Click me
</Button>
  `.trim();

  return (
    <CodeView 
      dependencies={{ Button }}
      language="jsx"
    >
      {code}
    </CodeView>
  );
}

Components

CodeView

The main component for displaying and executing React code.

import { CodeView } from '@react-code-view/react';

<CodeView
  dependencies={{ Button, Icon }}  // Components available in code
  language="jsx"                    // Syntax highlighting language
  editable={true}                   // Enable code editing
  renderPreview={true}              // Show live preview
  showLineNumbers={true}            // Show line numbers
  showCopyButton={true}             // Show copy button
  theme="rcv-theme-dark"            // Theme class
  beforeCompile={(code) => code}    // Transform before compile
  afterCompile={(code) => code}     // Transform after compile
  onChange={(code) => {}}           // Code change callback
  onError={(error) => {}}           // Error callback
>
  {sourceCode}
</CodeView>

Renderer

Syntax-highlighted code renderer.

import { Renderer } from '@react-code-view/react';

<Renderer
  code={sourceCode}
  language="typescript"
  showLineNumbers={true}
/>

MarkdownRenderer

Render markdown with syntax highlighting.

import { MarkdownRenderer } from '@react-code-view/react';

<MarkdownRenderer>
  {markdownContent}
</MarkdownRenderer>

CodeEditor

Editable code component with optional CodeMirror support.

import { CodeEditor } from '@react-code-view/react';

<CodeEditor
  code={sourceCode}
  onChange={(newCode) => setCode(newCode)}
  language="javascript"
  readOnly={false}
/>

Preview

Component for displaying executed code output.

import { Preview } from '@react-code-view/react';

<Preview error={error}>
  {renderedElement}
</Preview>

CopyCodeButton

Button to copy code to clipboard.

import { CopyCodeButton } from '@react-code-view/react';

<CopyCodeButton code={sourceCode} />

ErrorBoundary

Catch and display errors in child components.

import { ErrorBoundary } from '@react-code-view/react';

<ErrorBoundary onError={(error) => console.error(error)}>
  {children}
</ErrorBoundary>

Hooks

useCodeExecution

Hook for executing code and capturing rendered output.

import { useCodeExecution } from '@react-code-view/react';

function CustomCodeView({ initialCode, dependencies }) {
  const { element, error, code, setCode, execute } = useCodeExecution(
    initialCode,
    {
      dependencies,
      onError: (err) => console.error(err)
    }
  );

  return (
    <div>
      {error ? <pre>{error.message}</pre> : element}
      <textarea value={code} onChange={(e) => setCode(e.target.value)} />
    </div>
  );
}

Utilities

import { 
  canUseDOM,    // Check if DOM is available
  evalCode,     // Execute code string
  parseHTML,    // Parse HTML string
  parseDom,     // Parse DOM nodes
  mergeRefs     // Merge multiple refs
} from '@react-code-view/react';

Icons

import { CheckIcon, CodeIcon, CopyIcon } from '@react-code-view/react';

Theming

The package includes CSS custom properties for theming:

.rcv-code-view {
  --rcv-color-bg: #ffffff;
  --rcv-color-bg-code: #f6f8fa;
  --rcv-color-text: #24292f;
  --rcv-color-border: #d0d7de;
  --rcv-color-primary: #0969da;
  --rcv-color-error: #cf222e;
  /* ... more variables */
}

/* Dark theme */
.rcv-theme-dark {
  --rcv-color-bg: #0d1117;
  --rcv-color-bg-code: #161b22;
  /* ... */
}

License

MIT