chore: fetch to get in redux thunks files name
This commit is contained in:
23
redux/thunks/getAnalogInputsThunk.ts
Normal file
23
redux/thunks/getAnalogInputsThunk.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// /redux/thunks/getAnalogInputsThunk.ts
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchAnalogInputsService } from "@/services/fetchAnalogInputsService";
|
||||
import { setAnalogInputs } from "@/redux/slices/analogInputsSlice";
|
||||
|
||||
/**
|
||||
* Holt die analogen Eingänge von der API und speichert sie in Redux.
|
||||
*/
|
||||
export const getAnalogInputsThunk = createAsyncThunk(
|
||||
"analogeInputs/fetchAnalogInputs",
|
||||
async (_, { dispatch }) => {
|
||||
if (typeof window === "undefined") return; // Server-Side Execution blockieren
|
||||
try {
|
||||
const data = await fetchAnalogInputsService();
|
||||
console.log("📡 Analoge Eingänge geladen:", data);
|
||||
if (data) {
|
||||
dispatch(setAnalogInputs(data)); // ✅ Redux mit API-Daten füllen
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("❌ Fehler beim Laden der analogen Eingänge:", error);
|
||||
}
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user