28
loading...
This website collects cookies to deliver better user experience
<Select
loadingMessage={() => "Chargement…"}
noOptionsMessage={() => "Aucun résultat"}
placeholder="Choisissez une valeur"
// …
/>
MySelect
that has some default options. Since the only thing that changes for each instance are the name and the change handler, we need two props:export default function MySelect({ name, onChange }) {
return (
<Select
loadingMessage={() => "Chargement…"}
noOptionsMessage={() => "Aucun résultat"}
placeholder="Choisissez une valeur"
name={name}
onChange={onChange}
/>
);
}
<MySelect name="user" onChange={(v) => setUser(v)} />
<label>Liste des projets</label>
<MySelect
name="project"
onChange={(v) => setProject(v)}
/>
// Another file
<MySelect name="foo" onChange={bar} />
export default function MySelect({
name,
onChange,
value,
}) {
export default function MySelect({
name,
onChange,
value,
customStyles = [],
}) {
export default function MySelect({
name,
onChange,
value,
customStyles = [],
disabled = false,
// etc.
}) {
export default function MySelect(props) {
return (
<Select
loadingMessage={() => "Chargement…"}
noOptionsMessage={() => "Aucun résultat"}
placeholder="Choisissez une valeur"
{...props}
/>
);
}
<MySelect
isSearchable
isClearable
isMulti
name="products"
// …
/>
<MySelect
isSearchable
isClearable
isMulti
name="services"
// …
/>
<MySelect
isSearchable
isClearable
isMulti
name="things"
// …
/>
isSearchable
, isClearable
, isMulti
. We could create a new component that looks like MySelect
:export default function MySearchableSelect(props) {
return (
<Select
loadingMessage={() => "Chargement…"}
noOptionsMessage={() => "Aucun résultat"}
placeholder="Choisissez une valeur"
isSearchable
isClearable
isMulti
{...props}
/>
);
}
export default function MySearchableSelect(props) {
return (
<MySelect
isSearchable
isClearable
isMulti
{...props}
/>
);
}
export default function MySelect({
searchable = false
...props
}) {
let searchableProps = {};
if (searchable) {
searchableProps = {
isSearchable: true,
isClearable: true,
isMulti: true,
};
}
return (
<Select
loadingMessage={() => "Chargement…"}
noOptionsMessage={() => "Aucun résultat"}
placeholder="Choisissez une valeur"
{...searchableProps}
{...props}
/>
);
}