import * as React from 'react' ; import { HiHeart , HiOutlineHeart } from 'react-icons/hi' ; function SaveFavorite ( { productId } ) { const [ favorites , setFavorites ] = React . useState ( [ ] ) ; const favorite = favorites . includes ( productId ) ; function handleClick ( ) { if ( favorite ) { setFavorites ( favorites . filter ( ( id ) => id !== productId ) ) ; } else { setFavorites ( favorites . concat ( [ productId ] ) ) ; } } return ( < button className = "text-small as-link" onClick = { handleClick } > < span > Favorite < /span> { favorite ? < HiHeart color = "#f00" / > : < HiOutlineHeart />} < /button>); } export default SaveFavorite ;