mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-23 18:41:36 +01:00
21 lines
497 B
JavaScript
21 lines
497 B
JavaScript
import useStore, { createReport } from 'store/reports';
|
|
import { useCallback, useEffect, useState } from 'react';
|
|
|
|
export function useReport(reportId, defaultParameters) {
|
|
const [id, setId] = useState(reportId);
|
|
|
|
const selector = useCallback(state => state[id], [id]);
|
|
const report = useStore(selector);
|
|
|
|
useEffect(() => {
|
|
if (!report) {
|
|
const newReport = createReport(defaultParameters);
|
|
setId(newReport.id);
|
|
}
|
|
}, []);
|
|
|
|
return report;
|
|
}
|
|
|
|
export default useReport;
|