Browse Source
- Convert Yuan.tsx to FC with useRef + useEffect - Convert MonitorMap to FC with useState + useEffect - Convert autoHeight HOC to functional component - Convert WaterWave to FC with proper animation cleanup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>pull/11631/head
5 changed files with 316 additions and 364 deletions
@ -1,33 +1,17 @@ |
|||
import React from 'react'; |
|||
import { useEffect, useRef } from 'react'; |
|||
import { yuan } from '../components/Charts'; |
|||
/** 减少使用 dangerouslySetInnerHTML */ |
|||
export default class Yuan extends React.Component<{ |
|||
children: string | number; |
|||
}> { |
|||
main: HTMLSpanElement | undefined | null = null; |
|||
|
|||
componentDidMount() { |
|||
this.renderToHtml(); |
|||
} |
|||
|
|||
componentDidUpdate() { |
|||
this.renderToHtml(); |
|||
} |
|||
/** 减少使用 dangerouslySetInnerHTML */ |
|||
const Yuan: React.FC<{ children: string | number }> = ({ children }) => { |
|||
const spanRef = useRef<HTMLSpanElement>(null); |
|||
|
|||
renderToHtml = () => { |
|||
const { children } = this.props; |
|||
if (this.main) { |
|||
this.main.innerHTML = yuan(children); |
|||
useEffect(() => { |
|||
if (spanRef.current) { |
|||
spanRef.current.innerHTML = yuan(children); |
|||
} |
|||
}; |
|||
}, [children]); |
|||
|
|||
return <span ref={spanRef} />; |
|||
}; |
|||
|
|||
render() { |
|||
return ( |
|||
<span |
|||
ref={(ref) => { |
|||
this.main = ref; |
|||
}} |
|||
/> |
|||
); |
|||
} |
|||
} |
|||
export default Yuan; |
|||
|
|||
Loading…
Reference in new issue