0
function handleClick(){
    setCard()

    setTotalPrice();
}

This is the function that i pass as prop to the component.

<Receipt orders={card} totalPrice={totalPrice}/>

And watch it by useEffect on component side, but it only updates the card state. I can solve the problem with calculating totalPrice on Receipt component but just wondering why doesnt it update the states on children same time ?

const [orders, setOrders] = useState(props.orders);
const [tPrice, setTPrice] = useState(props.totalPrice);

useEffect(() => {
    setOrders(props.orders);
},[props.orders]);

useEffect(() => {
    setTPrice(props.totalPrice);
}, [props.totalPrice]);

Why does it update state of totalPrice next time calling function, instead of same time.

mfturkcan
  • 43
  • 1
  • 6

0 Answers0