scrimba
React Bootcamp Course
Custom Hover Hook
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Custom Hover Hook
AboutCommentsNotes
Custom Hover Hook
Expand for more info
components
CartItem.js
run
preview
console
import React, {useState, useContext} from "react"
import PropTypes from "prop-types"
import {Context} from "../Context"

function CartItem({item}) {
const [hovered, setHovered] = useState(false)
const {removeFromCart} = useContext(Context)

const iconClassName = hovered ? "ri-delete-bin-fill" : "ri-delete-bin-line"

return (
<div className="cart-item">
<i
className={iconClassName}
onClick={() => removeFromCart(item.id)}
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
>
</i>

<img src={item.url} width="130px" />
<p>$5.99</p>
</div>
)
}

CartItem.propTypes = {
item: PropTypes.shape({
url: PropTypes.string.isRequired
})
}

export default CartItem
Console
/cart
-8:58