0

How to pass props in a Link react router? I've tried multiple ways using state and location, but was unsuccessful.

const Footer = (props) => {

  const { cart, handleIncrement, handleDecrement, quantity } = props;

  const [toggle, setToggle] = useState(false);

  const cartPrice = cart.reduce((accum,item) => accum + item.qty * item.price, 0);
  const cartLength = cart.reduce((accum,item) => accum + item.qty, 0);

  const handleToggle = () => {
    setToggle(pre => !pre);
  }



  console.log(cart);
  return (
    <>
    <div className='footer'>
        <div className="left-sec">
            <div className="cart-details">
                <span className='cart-items'> {cartLength} Items</span>
                <span className='cart-price'>Total ₹{cartPrice} </span>
            </div>
            <button className="up" onClick={handleToggle}>
              ^
            </button>
        </div>
          <Link to='/checkout' className='login-sec'>
              <span className='heading'>Continue</span>
              <span className='arrow'>→</span>
          {console.log(cart)}
          </Link>
    </div>
    {toggle && <Cart cart={cart} quantity={quantity} handleIncrement={handleIncrement} handleDecrement={handleDecrement} cartPrice={cartPrice} close={()=> setToggle(false)}/>}
    </>
  )
}

export default Footer;

I want to pass cart, cartPrice, handleIncrement , handleDecrement to Link to checkout. please help me out.

Harshil Gambhir
  • 337
  • 1
  • 2
  • 8
  • Does this answer your question? [Pass props in Link react-router](https://stackoverflow.com/questions/30115324/pass-props-in-link-react-router) – Pavel Bely Aug 05 '22 at 18:54
  • Has you try [this?](https://stackoverflow.com/questions/30115324/pass-props-in-link-react-router) . It seems to work :) – shaked keynan Aug 05 '22 at 18:56

0 Answers0