1.0.1 • Published 7 months ago

better-react-select v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

better-react-select v1.0.0

A React Select component

Installation

npm i better-react-select

Code example

// import
import {Select} from "better-react-select/Select.tsx";

// example usage
interface IUser {
    id: number;
    name: string;
}

function App() {
    const [users, setUsers] = useState<IUser[]>([]);
    const [selectedUser, setSelectedUser] = useState<IUser>();


    return (
        <Select<IUser> items={users} optionTitle={"name"} optionValue={"id"} setSelectedItem={setSelectedUser} bg={"black"}/>
    ) 
}

Properties

Required
NameDescriptionType
itemsarray of objects that will be displayed in the select elementT[]
optionTitlename of the property that will be displayed as the text inside the option elementsstring
optionValuename of the property that will be used as the value attribute of the option elements; must be uniquestring
Optional
NameDescriptionType
setSelectedItem(item: T)function that sets the current selectedItemvoid
onChange(e: React.ChangeEvent)allows you to specify a custom onChange functionvoid
Style
NameDescriptionType
bgallows you to specify a backgroundColor for the select elementstring
1.0.1

7 months ago

1.0.0

7 months ago