From 9f7743c8f1fc2ed18b025ba19a052e9a319464af Mon Sep 17 00:00:00 2001 From: Ruidy Date: Mon, 5 Apr 2021 10:22:06 +0200 Subject: [PATCH] refactor --- src/store/meal/actions.ts | 2 -- src/store/meal/index.tsx | 14 ++++---------- src/store/meal/reducer.ts | 4 +++- 3 files changed, 7 insertions(+), 13 deletions(-) delete mode 100644 src/store/meal/actions.ts diff --git a/src/store/meal/actions.ts b/src/store/meal/actions.ts deleted file mode 100644 index 8a4da09..0000000 --- a/src/store/meal/actions.ts +++ /dev/null @@ -1,2 +0,0 @@ -export type Action = { type: "fetchMeal" | "fetchRandomMeal" | "toggleFav" }; -export type Dispatch = (action: Action) => void; diff --git a/src/store/meal/index.tsx b/src/store/meal/index.tsx index 7fabedb..b98ae56 100644 --- a/src/store/meal/index.tsx +++ b/src/store/meal/index.tsx @@ -2,18 +2,12 @@ import { createContext, FC, useContext, useReducer } from "react"; import { MealApi } from "../../types/meal"; -import { Dispatch } from "./actions"; -import { appReducer } from "./reducer"; - -const AppContext = createContext< - | { - state: AppState; - dispatch: Dispatch; - } - | undefined ->(undefined); +import { appReducer, Dispatch } from "./reducer"; export type AppState = { meals: MealApi[] }; +type ContextType = { state: AppState; dispatch: Dispatch } | undefined; + +const AppContext = createContext(undefined); export const useMeal = () => { const context = useContext(AppContext); diff --git a/src/store/meal/reducer.ts b/src/store/meal/reducer.ts index 554ad91..324bf21 100644 --- a/src/store/meal/reducer.ts +++ b/src/store/meal/reducer.ts @@ -1,4 +1,3 @@ -import { Action } from "./actions"; import { AppState } from "./index"; export const appReducer = (state: AppState, action: Action) => { @@ -14,3 +13,6 @@ export const appReducer = (state: AppState, action: Action) => { } } }; + +export type Action = { type: "fetchMeal" | "fetchRandomMeal" | "toggleFav" }; +export type Dispatch = (action: Action) => void;