Code Hike is an open-source library designed to enhance web content by transforming standard Markdown into rich, interactive experiences using React. Currently stable at version 1.1.0, the project demonstrates an active release cadence with frequent patch updates and a significant major release (v1.0.0) in August 2024. Its core functionality revolves around providing 'Fine-grained Markdown' and 'Headless codeblocks', which are key differentiators. Unlike traditional syntax highlighters, Code Hike parses the Abstract Syntax Tree (AST) of code blocks, enabling advanced features like line focusing, callouts, diffs, and interactive elements directly within code comments. This allows developers to build custom React components for rendering code and markdown, giving complete control over UI and behavior. It is built on the MDX ecosystem and integrates seamlessly with React-based frameworks like Next.js, making it ideal for code walkthroughs, tutorials, interactive blog posts, and comprehensive documentation sites.
npm install codehikeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core setup for Code Hike with MDX and a custom React Server Component for rendering code blocks with highlighting and annotations.
Consult the official migration guide for Code Hike v1.0. Incremental adoption is supported by using `ignoreCode` in your configuration to opt-in specific code blocks to v1.
Ensure your framework supports RSCs for components using `highlight`. If not, configure Code Hike to perform highlighting during the MDX compilation step by defining `syntaxHighlighting.theme` in `chConfig` directly in `next.config.mjs`.
Copy the required CSS variables from the Code Hike documentation for your chosen theme and include them in your project's global CSS, adapting selectors (e.g., `:root`, `@media (prefers-color-scheme: dark)`).
Code Hike is designed for React-based MDX setups. Consider using frameworks like Next.js, Remix, Docusaurus, Nextra, or Fuma Docs that are compatible.
Ensure all options passed to `remarkCodeHike` and `recmaCodeHike` in `next.config.mjs` are serializable. If issues persist, consider disabling Turbopack or using a stable version of Next.js that has proven compatibility. Report specific errors on the Code Hike GitHub.
Add `'use client'` at the top of the React component file that directly or indirectly uses `createContext` or other client-only React hooks/APIs.
Ensure the MDX compilation environment correctly provides the `file.history` or equivalent context that allows Code Hike to resolve relative file paths, especially when integrating with custom MDX loaders or bundler configurations.
Verify that your Markdown content uses the correct decoration syntax (e.g., `!decorationName`) and that the parsing logic in your React component correctly extracts and passes the `steps` prop. Review Code Hike's documentation examples for content structuring.