| 5 | import { useState } from 'react'; |
| 6 | |
| 7 | function App() { |
| 8 | |
| 9 | const changeHorseColorRef = useRef(() => {}); |
| 10 | |
| 11 | const [str, setStr] = useState(''); |
| 12 | |
| 13 | useEffect(() => { |
| 14 | const dom = document.getElementById('content'); |
| 15 | const { changeHorseColor } = init(dom, setStr); |
| 16 | |
| 17 | changeHorseColorRef.current = changeHorseColor; |
| 18 | |
| 19 | return () => { |
| 20 | dom.innerHTML = ''; |
| 21 | } |
| 22 | }, []); |
| 23 | |
| 24 | return <div> |
| 25 | <div id="header"> |
| 26 | React 和 Three.js |
| 27 | </div> |
| 28 | <div id="main"> |
| 29 | <div id="content"> |
| 30 | </div> |
| 31 | <div id="operate"> |
| 32 | <button onClick={()=> {changeHorseColorRef.current('pink')}}>粉色</button> |
| 33 | <button onClick={()=> {changeHorseColorRef.current('lightgreen')}}>绿色</button> |
| 34 | <button onClick={()=> {changeHorseColorRef.current('lightblue')}}>蓝色</button> |
| 35 | </div> |
| 36 | <div> |
| 37 | {str} |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | } |
| 42 | |
| 43 | export default App; |