What is @types/react-syntax-highlighter?
The @types/react-syntax-highlighter package provides TypeScript type definitions for the react-syntax-highlighter package. This allows developers using TypeScript to integrate syntax highlighting in their React applications with type safety, ensuring that the props and options they use with react-syntax-highlighter are correctly typed.
Syntax Highlighting in React Components
This code sample demonstrates how to use react-syntax-highlighter with TypeScript in a React component to highlight JavaScript code. It imports a specific syntax highlighting style and applies it to a code snippet.
import React from 'react';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { dark } from 'react-syntax-highlighter/dist/esm/styles/prism';
const Component = () => (
<SyntaxHighlighter language='javascript' style={dark}>
{`const a = 'Hello, world!';`}
</SyntaxHighlighter>
);