Skip to content

Commit e143b9a

Browse files
committed
fix(Bug): added condition for store hooks
1 parent e642e73 commit e143b9a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/hooks/useStore.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { store, actions } from "../store";
33

44
export const useStore = () => {
55
const { state, dispatch } = useContext(store);
6-
const dispatchAction = (action) => dispatch(action);
6+
7+
const dispatchAction = (action) => action && dispatch(action);
78

89
return { state, dispatchAction, actions };
910
};

src/pages/Login/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext } from "react";
1+
import React from "react";
22
import { useStore } from "../../hooks";
33

44
const Login = () => {
@@ -7,7 +7,7 @@ const Login = () => {
77
return (
88
<div>
99
<button
10-
onClick={() => dispatchAction(actions.setUserAuthenticated(true))}
10+
onClick={() => dispatchAction()}
1111
>
1212
Authenticate
1313
</button>

0 commit comments

Comments
 (0)