fix(hydration): PuaPanel placeholder 改用 useEffect 随机选取,修复 SSR/客户端 hydration 不匹配
This commit is contained in:
@@ -261,7 +261,11 @@ function PuaPanel({ gameReady, hc, waveStarted }: { gameReady: boolean; hc: numb
|
|||||||
const [insufficient, setInsufficient] = useState(false)
|
const [insufficient, setInsufficient] = useState(false)
|
||||||
const [dupWarning, setDupWarning] = useState<string | null>(null)
|
const [dupWarning, setDupWarning] = useState<string | null>(null)
|
||||||
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
||||||
const placeholder = useRef(PUA_PLACEHOLDERS[Math.floor(Math.random() * PUA_PLACEHOLDERS.length)]).current
|
const [placeholder, setPlaceholder] = useState(PUA_PLACEHOLDERS[0])
|
||||||
|
useEffect(() => {
|
||||||
|
// 只在客户端随机选取,避免 SSR/客户端 hydration 不匹配
|
||||||
|
setPlaceholder(PUA_PLACEHOLDERS[Math.floor(Math.random() * PUA_PLACEHOLDERS.length)])
|
||||||
|
}, [])
|
||||||
|
|
||||||
const cost = calcPuaCost(hc)
|
const cost = calcPuaCost(hc)
|
||||||
const canAfford = hc >= cost
|
const canAfford = hc >= cost
|
||||||
|
|||||||
Reference in New Issue
Block a user