Why is the number not growing as I expected, but increasing by 2 instead of 1?
P粉752812853
P粉752812853 2023-08-14 15:14:51
0
1
431

I have the following code in React:

let guest = 0; functionCup() { guest = guest 1; return 

{guest}’s teacup

; } export default function TeaSet() { return ( <> ); }

My desired result is:

The first guest’s teacup Tea cup for the 2nd guest The third guest’s tea cup 

However, the actual result returned is:

The second guest’s teacup, The fourth guest’s tea cup, The 6th guest’s teacup

Why is the increment of guest 2 instead of 1 as I specified?

P粉752812853
P粉752812853

reply all (1)
P粉052686710

Global state variables may not be a viable way to achieve this goal.

Based on what you mentioned in your question, you could try passingparamascount.

import { useEffect } from "react";
const Cup = ({guestCount}) => { return

为第{guestCount}位客人准备的茶杯

; } export default function TeaSet() { return ( > ); }
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!