fix: use useMemo instead of useState for repo/adapter initialization
Fixed TypeScript error by changing from useState to useMemo for repo and adapter initialization. This properly exposes the repo and adapter objects instead of returning a state setter function. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
f1acd09a4e
commit
ed5628029d
|
|
@ -100,7 +100,7 @@ export function useAutomergeSync(config: AutomergeSyncConfig): TLStoreWithStatus
|
||||||
return
|
return
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const [repo, adapter] = useState(() => {
|
const { repo, adapter } = useMemo(() => {
|
||||||
const adapter = new CloudflareNetworkAdapter(workerUrl, roomId, applyJsonSyncData)
|
const adapter = new CloudflareNetworkAdapter(workerUrl, roomId, applyJsonSyncData)
|
||||||
const repo = new Repo({
|
const repo = new Repo({
|
||||||
network: [adapter],
|
network: [adapter],
|
||||||
|
|
@ -113,8 +113,8 @@ export function useAutomergeSync(config: AutomergeSyncConfig): TLStoreWithStatus
|
||||||
console.log('🔄 CloudflareAdapter received message from network:', msg.type)
|
console.log('🔄 CloudflareAdapter received message from network:', msg.type)
|
||||||
})
|
})
|
||||||
|
|
||||||
return [repo, adapter] as const
|
return { repo, adapter }
|
||||||
})
|
}, [workerUrl, roomId, applyJsonSyncData])
|
||||||
|
|
||||||
// Initialize Automerge document handle
|
// Initialize Automerge document handle
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -261,7 +261,7 @@ export function useAutomergeSync(config: AutomergeSyncConfig): TLStoreWithStatus
|
||||||
return () => {
|
return () => {
|
||||||
mounted = false
|
mounted = false
|
||||||
}
|
}
|
||||||
}, [repo, roomId, adapter, workerUrl])
|
}, [repo, adapter, roomId, workerUrl])
|
||||||
|
|
||||||
// Track mouse state to prevent persistence during active mouse interactions
|
// Track mouse state to prevent persistence during active mouse interactions
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue