modal counter
P粉458725040
P粉458725040 2024-04-03 14:16:44
0
1
270

I'm trying to create a modal with a /-counter.

However, I think since the state is in the underlying component, the modal doesn't recognize it. Any idea how to fix it?

I tried passing it as a prop with no success

export default function ProgramCard() { const [count, setCount] = useState(0); const handleIncrement = () => { console.log(1) setCount(prevCount => prevCount + 1); }; const handleDecrement = () => { setCount(prevCount => prevCount - 1); }; const [opened, { open, close }] = useDisclosure(false); const openModal = () => modals.openConfirmModal({ title: 'Input Data', children: ( 
{" # "}{count}{" # "}
), labels: { confirm: 'Confirm', cancel: 'Cancel' }, onCancel: () => console.log('Cancel'), onConfirm: () => notifications.show({ title: 'Input Submitted', message: 'Complete', }), }); return ( Sample

) }

I tried passing it as a prop with no success

P粉458725040
P粉458725040

reply all (1)
P粉495955986

I think you just need to passhandleIncrement:

           

Due to the way closures work in javascript, no matter where you callhandleIncrement, it will still referencesetCount, which in turn referencescountInside the

Modal

component you may have a button

    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!