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;
        }}
      />
    );
  }
}