Skip to content

Commit

Permalink
fix(components): this should fix sentry error related to freshly upda…
Browse files Browse the repository at this point in the history
…ted 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)
  • Loading branch information
Kirill Bolotsky authored Oct 23, 2020
1 parent e1ce7a3 commit 4dbda50
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"gatsby-transformer-sharp": "^2.5.17",
"node-sass": "^4.14.1",
"prism-react-renderer": "^1.1.1",
"prop-types": "^15.7.2",
"qs": "^6.9.1",
"react": "^16.10.2",
"react-clipboard.js": "^2.0.16",
Expand Down
6 changes: 3 additions & 3 deletions src/components/shared/code/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ const Code = ({ children, showLineNumbers, showHeightToggler }) => {
}

return (
<WithCopyButton dataToCopy={children.props.children}>
<WithCopyButton dataToCopy={children.props?.children}>
<Highlight
{...defaultProps}
code={children.props.children}
language={getLanguageDeclaration(children?.props?.className)}
code={children.props?.children}
language={getLanguageDeclaration(children.props?.className)}
>
{({ className, tokens, getLineProps, getTokenProps }) => (
<pre
Expand Down
14 changes: 14 additions & 0 deletions src/components/shared/with-copy-button/with-copy-button.view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import Clipboard from 'react-clipboard.js';

Expand Down Expand Up @@ -28,3 +29,16 @@ export const WithCopyButton = ({
</div>
);
};

WithCopyButton.propTypes = {
children: PropTypes.node.isRequired,
dataToCopy: PropTypes.string,
wrapperLabel: PropTypes.string,
copyButtonLabel: PropTypes.string,
};

WithCopyButton.defaultProps = {
dataToCopy: '',
wrapperLabel: '',
copyButtonLabel: '',
};

0 comments on commit 4dbda50

Please sign in to comment.