-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeExample.js
More file actions
32 lines (26 loc) · 821 Bytes
/
Copy pathCodeExample.js
File metadata and controls
32 lines (26 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React from 'react';
import PropTypes from 'prop-types';
import hljs from 'highlight.js/lib/highlight'
import javascript from 'highlight.js/lib/languages/javascript'
// This way is easy, but adds 170K gzipped to bundle since all langs are included.
// import Highlight from 'react-highlight'
class CodeExample extends React.Component {
componentDidMount() {
hljs.registerLanguage('javascript', javascript);
hljs.highlightBlock(this.element);
}
render() {
console.log('rendered')
return (
<pre ref={ref => { this.element = ref }}>
<code>
{this.props.children}
</code>
</pre>
)
}
}
CodeExample.propTypes = {
children: PropTypes.string.isRequired
}
export default CodeExample;