Yuan.js 541 Bytes
Newer Older
jim's avatar
jim committed
1 2 3 4 5 6 7 8 9
import React from 'react';
import { yuan } from 'components/Charts';
/**
 * 减少使用 dangerouslySetInnerHTML
 */
export default class Yuan extends React.PureComponent {
  componentDidMount() {
    this.rendertoHtml();
  }
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
10

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

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

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