You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
762 B

2 years ago
  1. import { useState } from 'react'
  2. function getDefaultValue () {
  3. for (let i = 0; i < 10000; i++) {
  4. }
  5. return '10'
  6. }
  7. function Counter (props) {
  8. const [count, setCount] = useState(() => {
  9. /**
  10. * 初始值经过一定的计算
  11. * 只要无法直接确定需要通过一定的操作才能获取就可以理解为计算
  12. */
  13. // return props.count
  14. // 循环遍历一万条数据才能确定这里的初始值
  15. return getDefaultValue()
  16. })
  17. return (
  18. <button onClick={() => setCount(count + 1)}>{count}</button>
  19. )
  20. }
  21. function App () {
  22. return (
  23. <div>
  24. <Counter count={10}/>
  25. <Counter count={20}/>
  26. </div>
  27. )
  28. }
  29. export default App