chore: refactor class components to functional

This commit is contained in:
Alex Varchuk 2022-07-05 13:01:44 +03:00
parent 1c0b31415e
commit d85e55e04f

View File

@ -9,24 +9,21 @@ export interface SourceCodeProps {
lang: string; lang: string;
} }
export class SourceCode extends React.PureComponent<SourceCodeProps> { export const SourceCode = (props: SourceCodeProps) => {
render() { const { source, lang } = props;
const { source, lang } = this.props; return <StyledPre dangerouslySetInnerHTML={{ __html: highlight(source, lang) }} />;
return <StyledPre dangerouslySetInnerHTML={{ __html: highlight(source, lang) }} />; };
}
}
export class SourceCodeWithCopy extends React.Component<SourceCodeProps> { export const SourceCodeWithCopy = (props: SourceCodeProps) => {
render() { const { source, lang } = props;
return ( return (
<CopyButtonWrapper data={this.props.source}> <CopyButtonWrapper data={source}>
{({ renderCopyButton }) => ( {({ renderCopyButton }) => (
<SampleControlsWrap> <SampleControlsWrap>
<SampleControls>{renderCopyButton()}</SampleControls> <SampleControls>{renderCopyButton()}</SampleControls>
<SourceCode lang={this.props.lang} source={this.props.source} /> <SourceCode lang={lang} source={source} />
</SampleControlsWrap> </SampleControlsWrap>
)} )}
</CopyButtonWrapper> </CopyButtonWrapper>
); );
} };
}