Yuan.js 566 Bytes
Newer Older
jim's avatar
jim committed
1
import React from 'react';
ζ„šι“'s avatar
ζ„šι“ committed
2 3 4
import { Charts } from 'ant-design-pro';

const { yuan } = Charts;
jim's avatar
jim committed
5 6 7 8 9 10 11
/**
 * 减少使用 dangerouslySetInnerHTML
 */
export default class Yuan extends React.PureComponent {
  componentDidMount() {
    this.rendertoHtml();
  }
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
12

jim's avatar
jim committed
13 14 15
  componentDidUpdate() {
    this.rendertoHtml();
  }
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
16

jim's avatar
jim committed
17
  rendertoHtml = () => {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
18
    const { children } = this.props;
jim's avatar
jim committed
19
    if (this.main) {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
20
      this.main.innerHTML = yuan(children);
jim's avatar
jim committed
21 22
    }
  };
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
23

jim's avatar
jim committed
24 25 26 27 28 29 30 31 32 33
  render() {
    return (
      <span
        ref={ref => {
          this.main = ref;
        }}
      />
    );
  }
}