mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-25 08:06:51 +00:00
Switch to vite and preact
This commit is contained in:
20
src/app/hooks/useModel.ts
Normal file
20
src/app/hooks/useModel.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { DataModel } from '@mcschema/core'
|
||||
import { useEffect } from 'preact/hooks'
|
||||
|
||||
export function useModel(model: DataModel | undefined | null, invalidated: (model: DataModel) => unknown) {
|
||||
const listener = {
|
||||
invalidated() {
|
||||
if (model) {
|
||||
invalidated(model)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
model?.addListener(listener)
|
||||
listener.invalidated()
|
||||
return () => {
|
||||
model?.removeListener(listener)
|
||||
}
|
||||
}, [model])
|
||||
}
|
||||
Reference in New Issue
Block a user