(name: string)
| 12 | * legacy `useProjectV1Store().getProjectByName`. |
| 13 | */ |
| 14 | export const useAppProject = (name: string): Project => { |
| 15 | const getProjectByName = useAppStore((s) => s.getProjectByName); |
| 16 | const fetchProject = useAppStore((s) => s.fetchProject); |
| 17 | // Subscribe to the specific cache entry so the value recomputes once |
| 18 | // the project resolves. Selecting the raw entry (not the fallback) |
| 19 | // keeps the snapshot stable for `useSyncExternalStore`. |
| 20 | const cached = useAppStore((s) => s.projectsByName[name]); |
| 21 | useEffect(() => { |
| 22 | if (isValidProjectName(name)) { |
| 23 | void fetchProject(name); |
| 24 | } |
| 25 | }, [fetchProject, name]); |
| 26 | return useMemo( |
| 27 | () => getProjectByName(name), |
| 28 | [getProjectByName, name, cached] |
| 29 | ); |
| 30 | }; |
no test coverage detected