You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// NOTE for Next App Router: As long as you avoid using the useIsModalOpen hook and use
20
+
// modal.buttonProps instead of modal.open() the Modal component can be used as a
21
+
// server component (you can remove "use client";)
22
+
20
23
import { createModal } from "@codegouvfr/react-dsfr/Modal";
24
+
import { useIsModalOpen } from "@codegouvfr/react-dsfr/Modal/useIsModalOpen";
21
25
import { Button } from "@codegouvfr/react-dsfr/Button";
22
26
23
27
const modal = createModal({
@@ -26,23 +30,26 @@ const modal = createModal({
26
30
});
27
31
28
32
function Home(){
33
+
34
+
const isOpen = useIsModalOpen(modal);
35
+
36
+
console.log(\`Modal is currently: \${isOpen ? "open" : "closed"}\`);
37
+
29
38
return (
30
39
<>
31
40
{/* ... */}
32
41
<modal.Component title="foo modal title">
33
42
<h1>Foo modal content</h1>
34
43
</modal.Component>
35
-
<Button nativeButtonProps={fooModal.buttonProps}>Open foo modal</Button> {/* Use this if you are in a Server component (Next AppDir) and you don't want to add "use client"; just because of the the Modal */}
36
-
<Button onClick={fooModal.open}>Open foo modal</Button> {/* ...otherwise this works just as well and is more versatile */}
<Button nativeButtonProps={modal.buttonProps}>Open foo modal</Button> {/* Use this if you are in Next App Dir and you don't want to label the "use client"; the component hosting the Modal. */}
45
+
<Button onClick={()=> modal.open()}>Open foo modal</Button> {/* ...otherwise modal.open() works just as well and is more versatile */}
0 commit comments