DoneDeal0
DoneDeal0

Reputation: 6257

React-select: how to make creatable option optional?

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

Answers (1)

Yousaf
Yousaf

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

Related Questions