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
I think you just need to pass
handleIncrement
:Due to the way closures work in javascript, no matter where you call
ModalhandleIncrement
, it will still referencesetCount
, which in turn referencescount
Inside the
component you may have a button