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'; |
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() { |
/** 减少使用 dangerouslySetInnerHTML */ |
||||
this.renderToHtml(); |
const Yuan: React.FC<{ children: string | number }> = ({ children }) => { |
||||
} |
const spanRef = useRef<HTMLSpanElement>(null); |
||||
|
|
||||
renderToHtml = () => { |
useEffect(() => { |
||||
const { children } = this.props; |
if (spanRef.current) { |
||||
if (this.main) { |
spanRef.current.innerHTML = yuan(children); |
||||
this.main.innerHTML = yuan(children); |
|
||||
} |
} |
||||
}; |
}, [children]); |
||||
|
|
||||
|
return <span ref={spanRef} />; |
||||
|
}; |
||||
|
|
||||
render() { |
export default Yuan; |
||||
return ( |
|
||||
<span |
|
||||
ref={(ref) => { |
|
||||
this.main = ref; |
|
||||
}} |
|
||||
/> |
|
||||
); |
|
||||
} |
|
||||
} |
|
||||
|
|||||
Loading…
Reference in new issue