React Select

There are few options on how to include/import React Select into your project.

Install from NPM

Install the React Select Js library from command prompt from the root directory of the project:

npm i react-select

Import the React Select package.

import Select, { SingleValue, MultiValue } from 'react-select';

Below the example how to use the package and make it working React Select on any page.

React Select For Single value Select

const [statusOption, setStatusOption] = useState(null);
   
    const status = [
      { label: 'Published', value: 'Published' },
      { label: 'Coming Soon', value: 'Coming Soon' },
      { label: 'Expired', value: 'Expired' }
    ];

    const handleStatusChange = (selected) => {
       ...
    };

   <div className="col-span-6">
        <label className="form-label">Status</label>
        <Select
            options={status}
             onChange={handleStatusChange}
            value={statusOption}
        />
        <input
        type="hidden"
        {...register('status', { required: 'status is required.' })} 
        />
        {errors.status && (
            <span className="text-red-500">{errors.status.message}</span>
        )}
  </div> 

React Select For MultiValue Select

const [selectedContributors, setSelectedContributors] = useState([]);

const contributorsOptions = [
    { label: 'Declan Grieve', value: 'Declan Grieve', image: '/assets/images/avatar/user-1.png' },
    { label: 'Callum Burston', value: 'Callum Burston', image: '/assets/images/avatar/user-2.png' },
    { label: 'Liam White', value: 'Liam White', image: '/assets/images/avatar/user-3.png' },
    { label: 'Sophia Adams', value: 'Sophia Adams', image: '/assets/images/avatar/user-4.png' },
    { label: 'Ethan Thompson', value: 'Ethan Thompson', image: '/assets/images/avatar/user-5.png' },
    { label: 'Ava Wilson', value: 'Ava Wilson', image: '/assets/images/avatar/user-6.png' }
];

const handleContributorsChange = (selected) => {
    ...
};

<div className="col-span-12">
    <label className="form-label">Contributors</label>
    <Select
        options={contributorsOptions}
        isMulti
        onChange={handleContributorsChange}
        value={selectedContributors}
    />
    <input
        type="hidden"
        {...register('contributors', { required: 'Contributors is required.' })} 
    />
    {errors.contributors && (
        <span className="text-red-500">{errors.contributors.message}</span>
    )}
</div>
Receive the latest updates directly in your inbox!

Be the first to know about new updates and exclusive discounts. No spam, just great offers!

How about

A Custom Project?

With over 7 years of experienced team, we specialize in delivering custom projects for startups, blue-chip companies, and government agencies. We have successfully completed over 250+ projects, providing tailored solutions that meet the unique needs of each client.

Hire Us
Domiex Admin & Dashboards
230+

Total Pages

5+

Layouts

11+

Application

We provide quick support withing one business day to all of our customers.

© Domiex Created & Crafted by SRBThemes.