Skip to content

Commit 53c411c

Browse files
authored
Merge pull request #252 from FormidableLabs/remove-theme-dictionary-hook
Remove theme dictionary hook
2 parents 20631f4 + 3cfe239 commit 53c411c

File tree

4 files changed

+18
-32
lines changed

4 files changed

+18
-32
lines changed

.changeset/slow-kiwis-return.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"prism-react-renderer": patch
3+
---
4+
5+
Remove client side hooks

packages/prism-react-renderer/src/components/highlight.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { InternalHighlightProps } from "../types"
2-
import { useThemeDictionary } from "./useThemeDictionary"
32
import { useGetLineProps } from "./useGetLineProps"
43
import { useGetTokenProps } from "./useGetTokenProps"
54
import { useTokenize } from "./useTokenize"
5+
import themeToDict from "../utils/themeToDict"
66

77
export const Highlight = ({
88
children,
@@ -12,7 +12,7 @@ export const Highlight = ({
1212
prism,
1313
}: InternalHighlightProps) => {
1414
const language = _language.toLowerCase()
15-
const themeDictionary = useThemeDictionary(language, theme)
15+
const themeDictionary = themeToDict(theme, language)
1616
const getLineProps = useGetLineProps(themeDictionary)
1717
const getTokenProps = useGetTokenProps(themeDictionary)
1818
const grammar = prism.languages[language]

packages/prism-react-renderer/src/components/useThemeDictionary.ts

-24
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EnvConfig, Language, PrismGrammar, PrismLib } from "../types"
22
import normalizeTokens from "../utils/normalizeTokens"
3-
import { useMemo, useRef } from "react"
3+
import { useMemo } from "react"
44

55
type Options = {
66
prism: PrismLib
@@ -10,7 +10,6 @@ type Options = {
1010
}
1111

1212
export const useTokenize = ({ prism, code, grammar, language }: Options) => {
13-
const prismRef = useRef(prism)
1413
return useMemo(() => {
1514
if (grammar == null) return normalizeTokens([code])
1615

@@ -21,9 +20,15 @@ export const useTokenize = ({ prism, code, grammar, language }: Options) => {
2120
tokens: [],
2221
}
2322

24-
prismRef.current.hooks.run("before-tokenize", prismConfig)
25-
prismConfig.tokens = prismRef.current.tokenize(code, grammar)
26-
prismRef.current.hooks.run("after-tokenize", prismConfig)
23+
prism.hooks.run("before-tokenize", prismConfig)
24+
prismConfig.tokens = prism.tokenize(code, grammar)
25+
prism.hooks.run("after-tokenize", prismConfig)
2726
return normalizeTokens(prismConfig.tokens)
28-
}, [code, grammar, language])
27+
}, [
28+
code,
29+
grammar,
30+
language,
31+
// prism is a stable import
32+
prism,
33+
])
2934
}

0 commit comments

Comments
 (0)