-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add product to favourites #16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also remove unused code instead of pushing comments
src/components/Card.tsx
Outdated
}; // See if the product id is in the favoriteItems array | ||
|
||
const handleClick = (currentProduct: IProduct) => { | ||
if (hasProductId(currentProduct._id)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use one action, toggleFavorite, where u will check is product in fav by id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at my last PR and implement a local storage feature as well.
src/pages/FavouritesPage.tsx
Outdated
|
||
// eslint-disable-next-line no-console | ||
// const [products, setProducts] = useState<IProduct[]>([]); | ||
// #endregion | ||
|
||
// #region rewrite to RTQ Query | ||
useEffect(() => { | ||
axios | ||
.get('https://dreamteam.onrender.com/products', { | ||
params: { page: 1, perPage: 8 }, | ||
}) | ||
.then((res) => { | ||
setProducts(res.data.data); | ||
}) | ||
.catch((e) => { | ||
throw new Error(e); | ||
}); | ||
}, []); | ||
// useEffect(() => { | ||
// axios | ||
// .get('https://dreamteam.onrender.com/products', { | ||
// params: { page: 1, perPage: 8 }, | ||
// }) | ||
// .then((res) => { | ||
// setProducts(res.data.data); | ||
// }) | ||
// .catch((e) => { | ||
// throw new Error(e); | ||
// }); | ||
// }, []); | ||
// #endregion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please delete comments
src/hooks/useLocalStorage.ts
Outdated
import { useEffect } from 'react'; | ||
import { getInitialFavourites, useAppDispatch } from '../redux/'; | ||
|
||
export const useInitFavourites = () => { | ||
const dispatch = useAppDispatch(); | ||
|
||
useEffect(() => { | ||
dispatch(getInitialFavourites()); | ||
}, []); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GJ, but, please, rename file to your hook name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
No description provided.