@@ -332,6 +332,70 @@ modalElement.presentingElement = await modalController.getTop(); // Get the top-
332332### React
333333
334334` ` ` tsx
335+ /* Using with useIonModal Hook */
336+
337+ import React , { useState } from ' react' ;
338+ import { IonButton , IonContent , IonPage , useIonModal } from ' @ionic/react' ;
339+
340+ const Body: React .FC <{
341+ count: number ;
342+ onDismiss : () => void ;
343+ onIncrement : () => void ;
344+ }> = ({ count, onDismiss, onIncrement }) => (
345+ < div>
346+ count: {count}
347+ < IonButton expand= " block" onClick= {() => onIncrement ()}>
348+ Increment Count
349+ < / IonButton>
350+ < IonButton expand= " block" onClick= {() => onDismiss ()}>
351+ Close
352+ < / IonButton>
353+ < / div>
354+ );
355+
356+ const ModalExample: React .FC = () => {
357+ const [count , setCount ] = useState (0 );
358+
359+ const handleIncrement = () => {
360+ setCount (count + 1 );
361+ };
362+
363+ const handleDismiss = () => {
364+ dismiss ();
365+ };
366+
367+ /**
368+ * First parameter is the component to show, second is the props to pass
369+ */
370+ const [present , dismiss ] = useIonModal (Body, {
371+ count,
372+ onDismiss: handleDismiss,
373+ onIncrement: handleIncrement,
374+ });
375+
376+ return (
377+ < IonPage>
378+ < IonContent fullscreen>
379+ < IonButton
380+ expand= " block"
381+ onClick= {() => {
382+ present ({
383+ cssClass: ' my-class' ,
384+ });
385+ }}
386+ >
387+ Show Modal
388+ < / IonButton>
389+ < div> Count: {count}< / div>
390+ < / IonContent>
391+ < / IonPage>
392+ );
393+ };
394+ ` ` `
395+
396+ ` ` ` tsx
397+ /* Using with IonModal Component */
398+
335399import React , { useState } from ' react' ;
336400import { IonModal , IonButton , IonContent } from ' @ionic/react' ;
337401
0 commit comments