Yuan.js 543 Bytes
Newer Older
jim's avatar
jim committed
1
import React from 'react';
2
import { yuan } from '@/components/Charts';
jim's avatar
jim committed
3 4 5 6 7 8 9
/**
 * 减少使用 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;
        }}
      />
    );
  }
}