Semantic UI React

2.1.5 · active · verified Sun Apr 19

Semantic UI React is the official React integration for the Semantic UI framework, providing a comprehensive collection of UI components designed to deliver consistent and aesthetically pleasing user interfaces. The current stable version is 2.1.5, with active development on a v3.0.0 beta branch, indicating ongoing maintenance and future feature enhancements. The library distinguishes itself through its declarative API, allowing developers to construct complex UIs with concise JSX. It heavily leverages 'shorthand props,' enabling a more compact and readable component tree by accepting primitive values or objects to render sub-components, which is a key differentiator. It also ships with first-class TypeScript support, offering robust type definitions for all its components and props, making it highly compatible with modern typed React workflows. While it requires the Semantic UI CSS toolkit for styling, it provides the React component logic, facilitating rapid development of visually consistent web applications. The release cadence for stable versions is moderate, with more frequent bug fixes and beta updates for the next major version. This package is an excellent choice for projects seeking a complete, opinionated UI toolkit with a strong emphasis on consistent design and developer experience within the React ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic React form using Semantic UI React components, including input fields, a button, and messages. It shows state management with React hooks and how to include the necessary Semantic UI CSS stylesheet for proper styling.

import React, { useState } from 'react';
import ReactDOM from 'react-dom/client';
import { Button, Form, Segment, Grid, Message } from 'semantic-ui-react';
import 'semantic-ui-css/semantic.min.css'; // Don't forget to include Semantic UI CSS!

function App() {
  const [name, setName] = useState('');
  const [email, setEmail] = useState('');
  const [submitted, setSubmitted] = useState(false);

  const handleSubmit = () => {
    setSubmitted(true);
    console.log({ name, email });
    // In a real app, you would send this data to a server
  };

  return (
    <Grid centered columns={2} style={{ marginTop: '5em' }}>
      <Grid.Column>
        <Segment>
          <Message
            attached
            header='Welcome to our site!'
            content='Fill out the form below to sign-up for a new account'
          />
          <Form className='attached fluid segment' onSubmit={handleSubmit}>
            <Form.Input
              label='Name'
              placeholder='First Name'
              value={name}
              onChange={(e) => setName(e.target.value)}
              required
            />
            <Form.Input
              label='Email'
              placeholder='example@domain.com'
              type='email'
              value={email}
              onChange={(e) => setEmail(e.target.value)}
              required
            />
            <Button primary type='submit'>Submit</Button>
          </Form>
          {submitted && (
            <Message success>
              <Message.Header>Form Submitted</Message.Header>
              <p>Name: {name}, Email: {email}</p>
            </Message>
          )}
        </Segment>
      </Grid.Column>
    </Grid>
  );
}

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(<App />);

view raw JSON →