新增统计饼图显示;调整组件结构

This commit is contained in:
JIANG
2025-12-18 16:54:07 +08:00
parent 5cc7275186
commit 9134dff67c
5 changed files with 312 additions and 49 deletions
@@ -0,0 +1,39 @@
"use client";
import React, { createContext, useContext, useState, ReactNode, Dispatch, SetStateAction } from "react";
import { PredictionResult } from "./types";
interface HealthRiskContextType {
predictionResults: PredictionResult[];
setPredictionResults: Dispatch<SetStateAction<PredictionResult[]>>;
currentYear: number;
setCurrentYear: Dispatch<SetStateAction<number>>;
}
const HealthRiskContext = createContext<HealthRiskContextType | undefined>(undefined);
export const HealthRiskProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
const [predictionResults, setPredictionResults] = useState<PredictionResult[]>([]);
const [currentYear, setCurrentYear] = useState<number>(4);
return (
<HealthRiskContext.Provider
value={{
predictionResults,
setPredictionResults,
currentYear,
setCurrentYear,
}}
>
{children}
</HealthRiskContext.Provider>
);
};
export const useHealthRisk = () => {
const context = useContext(HealthRiskContext);
if (context === undefined) {
throw new Error("useHealthRisk must be used within a HealthRiskProvider");
}
return context;
};