alsoscotland / react-super-select

MIT License
95 stars 33 forks source link

initialValue as empty array or empty object #129

Closed robinprashanth closed 6 years ago

robinprashanth commented 6 years ago

I am working on a project were the select option is optional in the create form. In Edit form, I need to set initialValue based on the API response. Is there any option to pass empty array or object to reactsuperselect.

Example constructor(props) { super(props); this.state = { errors: {}, recNumberInitialValue: undefined }; } componentDidMount(){ getAPIrequest.then((resp) => thissetState({recNumberInitialValue: resp})) }

<ReactSuperSelect className="form-input" dataSource={this.recNumbers} onChange={this.recHandler} deselectOnSelectedOptionClick={false} initialValue={this.state.recNumberInitialValue} clearable={false} />

here recNumberInitialValue is undefined or a value based on the API response.

I am getting Failed prop type: Invalid prop initialValue supplied to ReactSuperSelect.

Can you suggest If i can pass empty object or array as intialValue?

alsoscotland commented 6 years ago

@robinprashanth The code should handle the case where

 initialValue={undefined}

I think empty array should be fine as well.
Another option would be to simply not render super select at all if no options are available

robinprashanth commented 6 years ago

I have to show super select even if it's not having any initialValue. If i pass empty array it breaks with error : name property was not found

alsoscotland commented 6 years ago

Is there a reason you are not able to just leave initialValue undefined?

robinprashanth commented 6 years ago

Undefined did the trick.Thanks for the help.

alsoscotland commented 6 years ago

No problem @robinprashanth