|
1 |
| -import React from 'react' |
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | + |
2 | 4 |
|
3 | 5 | class Console extends React.Component {
|
4 |
| - componentDidUpdate(prevProps, prevState) { |
5 |
| - console.log("Console did update", this.props.instanceId, this.props.logs.toArray()); |
6 |
| - if (this.props.instanceId) { |
7 |
| - this.timer = setTimeout(this.props.queryBuildLogs.bind(this, this.props.instanceId), 3000); |
8 |
| - } |
| 6 | + static propTypes = { |
| 7 | + instanceId: PropTypes.string.isRequired, |
| 8 | + logs: PropTypes.arrayOf(PropTypes.any).isRequired, |
| 9 | + queryBuildLogs: PropTypes.func.isRequired, |
9 | 10 | }
|
10 |
| - |
11 |
| - shouldComponentUpdate(nextProps, nextState) { |
| 11 | + shouldComponentUpdate(nextProps) { |
12 | 12 | if (this.props.instanceId === nextProps.instanceId && this.props.logs === nextProps.logs) {
|
13 | 13 | return false;
|
14 | 14 | }
|
15 | 15 | return true;
|
16 | 16 | }
|
| 17 | + componentDidUpdate() { |
| 18 | + console.log('Console did update', this.props.instanceId, this.props.logs.toArray()); |
| 19 | + if (this.props.instanceId) { |
| 20 | + this.timer = setTimeout(this.props.queryBuildLogs.bind(this, this.props.instanceId), 3000); |
| 21 | + } |
| 22 | + } |
17 | 23 |
|
18 | 24 | render() {
|
19 |
| - var logs = this.props.logs.toArray().reverse().map((log, id) => { |
| 25 | + const logs = this.props.logs.toArray().reverse().map((log) => { |
20 | 26 | log = {
|
21 |
| - __html: log.replace(/\n/g, "<br>") |
| 27 | + __html: log.replace(/\n/g, '<br>'), |
22 | 28 | };
|
23 |
| - return (<div key={ id } dangerouslySetInnerHTML={ log }> |
24 |
| - </div>) |
25 |
| - }) |
| 29 | + return <div key={log} dangerouslySetInnerHTML={log} />; |
| 30 | + }); |
26 | 31 | return (
|
27 | 32 | <div className="realworld-build-console">
|
28 | 33 | { logs }
|
29 |
| - </div>) |
| 34 | + </div>); |
30 | 35 | }
|
31 | 36 | }
|
32 | 37 |
|
33 |
| - |
34 |
| -export default Console |
| 38 | +export default Console; |
0 commit comments