Skip to content

Commit

Permalink
feat: simulate heavy computation
Browse files Browse the repository at this point in the history
  • Loading branch information
q-u-n committed Jun 2, 2024
1 parent f833369 commit 13d5900
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions examples/react-query/compiler/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
"use client"
'use client'

import { useState } from "react"
import { useState } from 'react'

const Component = () => {
console.log('re-render')
return <div>Component</div>
}

// 模拟繁重的 JS 逻辑
function simulateHeavyComputation() {
console.log('simulateHeavyComputation')
const start = performance.now()
while (performance.now() - start < 2) {}
return 'mock res'
}

export default function Home() {
const [count, setCount] = useState(0)

const res = simulateHeavyComputation() // 这里要真正被组件中用到

return (
<>
<span>count: {count} </span>
<button onClick={() => setCount(count => count + 1)}>+1</button>
<button onClick={() => setCount((count) => count + 1)}>+1</button>
<Component />
{res}
</>
)
}
}

0 comments on commit 13d5900

Please sign in to comment.