Skip to content

Commit 4dbda50

Browse files
author
Kirill Bolotsky
authored
fix(components): this should fix sentry error related to freshly updated Code block (#142)
Added optional chaining in a few places, set up prop types for WithCopyButton, added prop-types as a project dep (not sure why we haven't been having this one yet)
1 parent e1ce7a3 commit 4dbda50

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"gatsby-transformer-sharp": "^2.5.17",
5757
"node-sass": "^4.14.1",
5858
"prism-react-renderer": "^1.1.1",
59+
"prop-types": "^15.7.2",
5960
"qs": "^6.9.1",
6061
"react": "^16.10.2",
6162
"react-clipboard.js": "^2.0.16",

src/components/shared/code/code.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ const Code = ({ children, showLineNumbers, showHeightToggler }) => {
5757
}
5858

5959
return (
60-
<WithCopyButton dataToCopy={children.props.children}>
60+
<WithCopyButton dataToCopy={children.props?.children}>
6161
<Highlight
6262
{...defaultProps}
63-
code={children.props.children}
64-
language={getLanguageDeclaration(children?.props?.className)}
63+
code={children.props?.children}
64+
language={getLanguageDeclaration(children.props?.className)}
6565
>
6666
{({ className, tokens, getLineProps, getTokenProps }) => (
6767
<pre

src/components/shared/with-copy-button/with-copy-button.view.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import classNames from 'classnames';
2+
import PropTypes from 'prop-types';
23
import React from 'react';
34
import Clipboard from 'react-clipboard.js';
45

@@ -28,3 +29,16 @@ export const WithCopyButton = ({
2829
</div>
2930
);
3031
};
32+
33+
WithCopyButton.propTypes = {
34+
children: PropTypes.node.isRequired,
35+
dataToCopy: PropTypes.string,
36+
wrapperLabel: PropTypes.string,
37+
copyButtonLabel: PropTypes.string,
38+
};
39+
40+
WithCopyButton.defaultProps = {
41+
dataToCopy: '',
42+
wrapperLabel: '',
43+
copyButtonLabel: '',
44+
};

0 commit comments

Comments
 (0)