JS/ TS
// Eksempel på integration i axios, NextJS-TS
import { useQuery } from "react-query";
import axios from "axios";
interface inputProps {
daysahead: number;
pricearea: string;
energysource: string;
}
const getPrediction = async ({
daysahead,
energysource,
pricearea,
}: inputProps) => {
const { data } = await axios.get(
`${process.env.NEXT_PUBLIC_API_BASE}/openapi/get_predict`,
{
params: {
daysahead: daysahead,
energysource: energysource,
region: pricearea,
},
headers: {
"apikey": `{{ api-key }}`,
"username": `{{ username }}`,
},
}
);
return data;
};
function usePrediction({ daysahead, pricearea, energysource }: inputProps) {
return useQuery(["prediction", pricearea, energysource, daysahead], () =>
getPrediction({ daysahead, energysource, pricearea })
);
}
export default usePrediction;
Last updated