Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
mxkxf committed Dec 10, 2024
1 parent 7c755ff commit 2480ddb
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/components/FeedProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ type Action =
type: "TOGGLE_READ_ALL_ITEMS";
index: number;
read: boolean;
};
}
| { type: "NOOP" };

function reducer(state: State, action: Action) {
switch (action.type) {
Expand Down Expand Up @@ -200,7 +201,7 @@ function useReducerWithMiddleware(
): [State, Dispatch<Action>] {
const [state, dispatch] = useReducer(reducer, initialState, initialiser);

const aRef = useRef<Action>();
const aRef = useRef<Action>({ type: "NOOP" });

const dispatchWithMiddleware = (action: Action) => {
middlewareFns.forEach((middlewareFn) => middlewareFn(action, state));
Expand All @@ -211,15 +212,11 @@ function useReducerWithMiddleware(
};

useEffect(() => {
if (typeof aRef.current === "undefined") {
return;
}

afterwareFns.forEach((afterwareFn) =>
afterwareFn(aRef.current as Action, state)
);

aRef.current = undefined;
aRef.current = { type: "NOOP" };
}, [afterwareFns, state]);

return [state, dispatchWithMiddleware];
Expand Down

0 comments on commit 2480ddb

Please sign in to comment.