新增统计饼图显示;调整组件结构
This commit is contained in:
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user