2

I cannot use Dropdown/Modal from Semantic UI in Next.js. The code below can't work properly (no response when clicking the button)

'use client';

import Image from "next/image";
import * as React from "react";
import { Button, Header, Modal, Icon } from "semantic-ui-react";

export default function Home() {
  const [open, setOpen] = React.useState(false);

  return (
    <div className="centered">
      <Icon size="massive" name="world" />
      <div className="separator" />
      <Modal
        onClose={() => setOpen(false)}
        onOpen={() => setOpen(true)}
        open={open}
        trigger={<Button>Show Modal</Button>}
      >
        <Modal.Header>Select a Photo</Modal.Header>
        <Modal.Content image>
          <span style={{ marginRight: 21 }}>
            <Image src="/image.png" width={400} height={266} />
          </span>
          <Modal.Description>
            <Header>Default Profile Image</Header>
            <p>
              We've found the following gravatar image associated with your
              e-mail address.
            </p>
            <p>Is it okay to use this photo?</p>
          </Modal.Description>
        </Modal.Content>
        <Modal.Actions>
          <Button color="black" onClick={() => setOpen(false)}>
            Nope
          </Button>
          <Button
            content="Yep, that's me"
            labelPosition="right"
            icon="checkmark"
            onClick={() => setOpen(false)}
            positive
          />
        </Modal.Actions>
      </Modal>
    </div>
  );
}

I've googled a lot, but cannot find any examples with Semantic UI with the APP router. Please help.

1 Answer 1

0

Add onClick={() => setOpen(true)} into your trigger button

trigger={<Button>Show Modal</Button>} to trigger={<Button onClick={() => setOpen(true)}>Show Modal</Button>}

Codesandbox: https://codesandbox.io/p/devbox/demo-next-cx577m?file=%2Fapp%2Fpage.tsx%3A3%2C32

Sign up to request clarification or add additional context in comments.

2 Comments

I tried it just now, but there is no difference :(
Check this codesandbox codesandbox.io/p/devbox/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.