@@ -2,23 +2,15 @@ import classNames from 'classnames';
2
2
import { WithCopyButton } from 'components/shared/with-copy-button' ;
3
3
import Highlight , { defaultProps } from 'prism-react-renderer' ;
4
4
import PropTypes from 'prop-types' ;
5
- import React , { useLayoutEffect , useRef , useState } from 'react' ;
5
+ import React from 'react' ;
6
6
7
7
import styles from './code.module.scss' ;
8
8
9
9
const Code = ( { children, showLineNumbers } ) => {
10
10
if ( ! children ) return null ;
11
- const codeContainerRef = useRef ( null ) ;
12
- const [ codeToCopy , setCodeToCopy ] = useState ( '' ) ;
13
11
14
- useLayoutEffect ( ( ) => {
15
- if ( codeContainerRef . current ) {
16
- setCodeToCopy ( codeContainerRef . current . textContent ) ;
17
- }
18
- } , [ codeContainerRef ] ) ;
19
-
20
- return codeToCopy ? (
21
- < WithCopyButton dataToCopy = { codeToCopy } >
12
+ return (
13
+ < WithCopyButton dataToCopy = { children . props . children } >
22
14
< Highlight
23
15
{ ...defaultProps }
24
16
code = { children . props . children }
@@ -52,13 +44,6 @@ const Code = ({ children, showLineNumbers }) => {
52
44
) }
53
45
</ Highlight >
54
46
</ WithCopyButton >
55
- ) : (
56
- < div
57
- style = { { position : 'absolute' , visibility : 'hidden' } }
58
- ref = { codeContainerRef }
59
- >
60
- { children . props . children }
61
- </ div >
62
47
) ;
63
48
} ;
64
49
0 commit comments