Skip to content

Commit ebeaf11

Browse files
Kirill BolotskyPepe Cano
authored andcommitted
refact: removed unnecessary logic from code component
1 parent 791cfee commit ebeaf11

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

src/components/shared/code/code.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,15 @@ import classNames from 'classnames';
22
import { WithCopyButton } from 'components/shared/with-copy-button';
33
import Highlight, { defaultProps } from 'prism-react-renderer';
44
import PropTypes from 'prop-types';
5-
import React, { useLayoutEffect, useRef, useState } from 'react';
5+
import React from 'react';
66

77
import styles from './code.module.scss';
88

99
const Code = ({ children, showLineNumbers }) => {
1010
if (!children) return null;
11-
const codeContainerRef = useRef(null);
12-
const [codeToCopy, setCodeToCopy] = useState('');
1311

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}>
2214
<Highlight
2315
{...defaultProps}
2416
code={children.props.children}
@@ -52,13 +44,6 @@ const Code = ({ children, showLineNumbers }) => {
5244
)}
5345
</Highlight>
5446
</WithCopyButton>
55-
) : (
56-
<div
57-
style={{ position: 'absolute', visibility: 'hidden' }}
58-
ref={codeContainerRef}
59-
>
60-
{children.props.children}
61-
</div>
6247
);
6348
};
6449

0 commit comments

Comments
 (0)