score:3

Accepted answer
const handleChecked = (id) => (e) => {
    const tempData1=[];
    const { checkedID } = e.target;
    const vID = e.currentTarget.id.split('-', 1);
    tempData1.push({ productId:itemID, variantId:vID})
    setChecked((values) => ({ ...values, [id]: checkedID, }));
    setVariant((prev) => ([...prev, ...tempData1]));
};

score:1

const handleChecked = (id) => (e) => {
      const { checkedID } = e.target;
      const vID = e.currentTarget.id.split('-', 1);
      setChecked((values) => ({ ...values, [id]: checkedID, }));
      setVariant((variant) => { return [...variant,{ productId:itemID, variantId:vID}]}); // variant always give the last value.
    };

score:1

const [variant, setVariant] = useState([]);

.
.
.

setVariant([...variant, ...tempData1]);

Related Query

More Query from same tag