| 277 | * Watches for changes to a file at a specific path |
| 278 | */ |
| 279 | export function useFilePath(store: FileSystemStore, path: string) { |
| 280 | const [node, setNode] = useState<FileNode | undefined>(() => store.getByPath(path)); |
| 281 | |
| 282 | useEffect(() => { |
| 283 | setNode(store.getByPath(path)); |
| 284 | |
| 285 | const unsubscribe = store.subscribe((event: FileSystemEvent) => { |
| 286 | if (event.path === path || event.type === 'store_reset') { |
| 287 | setNode(store.getByPath(path)); |
| 288 | } |
| 289 | }); |
| 290 | |
| 291 | return unsubscribe; |
| 292 | }, [store, path]); |
| 293 | |
| 294 | return node; |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Folder children Hook |