Reputation: 6257
I have a react-select component. I know it is possible to use <CreatableSelect/>
so as to add custom options. But how to make such a behaviour optional? I would like to have something like <Select creatable={true}/>
. Is it possible?
Upvotes: 1
Views: 615
Reputation: 29282
You could create a higher order component which will take the createable
prop and will return the Createable
select component if createable
prop is true otherwise will return the normal Select
component
function SelectHOC({createable, options}) {
return (
{ createable
? <CreatableSelect options={options} />
: <Select options={options} />
}
);
}
Upvotes: 2