Skip to content

Instantly share code, notes, and snippets.

@awran5
Created October 26, 2020 14:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awran5/b2fb99b91d279b700aff6d3a0f1f223d to your computer and use it in GitHub Desktop.
Save awran5/b2fb99b91d279b700aff6d3a0f1f223d to your computer and use it in GitHub Desktop.
Prismjs syntax highlighting with React TypeScript example

1. Install

npm i prismjs
npm i -D @types/prismjs

2. Import

import React, { useEffect } from 'react'
import Prism from 'prismjs'
import 'prismjs/components/prism-javascript' // Language
import 'prismjs/themes/prism-okaidia.css' // Theme

function App() {

  // Init
  useEffect(() => {
    Prism.highlightAll()
  }, [])
  
  // Usage
  return (
     <div className="App">
        <pre>
          <code className="language-javascript">
            &lt;div&gt; Markup here... &lt;/div&gt;
          </code>
        </pre>
     </div>
  )
}

export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment