Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  65] [ 2]  / answers: 1 / hits: 17508  / 8 Years ago, thu, july 14, 2016, 12:00:00

I am using ReactSelect in one of my forms:



<Select name='event-title' className=event-title ref=stateSelect autofocus optionsComponent={DropdownOptions} onInputChange={this.handleChangeTitle} options={this.state.titleResults} simpleValue clearable={this.state.clearable} name=selected-state  value={this.state.selectedTitleValue} onChange={this.handleTitleChosen} searchable={this.state.searchable} />


I'd like to to render a custom optionsComponent:



optionsComponent={DropdownOptions}


By looking at the example, you are able to render a custom component so I have tested that:



const DropdownOptions = React.createClass({
propTypes: {
children: React.PropTypes.node,
className: React.PropTypes.string,
isDisabled: React.PropTypes.bool,
isFocused: React.PropTypes.bool,
isSelected: React.PropTypes.bool,
onFocus: React.PropTypes.func,
onSelect: React.PropTypes.func,
option: React.PropTypes.object.isRequired,
},
handleMouseDown (event) {
event.preventDefault();
event.stopPropagation();
this.props.onSelect(this.props.option, event);
},
handleMouseEnter (event) {
this.props.onFocus(this.props.option, event);
},
handleMouseMove (event) {
if (this.props.isFocused) return;
this.props.onFocus(this.props.option, event);
},
render () {
return (
<div className={this.props.className}
onMouseDown={this.handleMouseDown}
onMouseEnter={this.handleMouseEnter}
onMouseMove={this.handleMouseMove}
title={this.props.option.title}>
<span>Testing Text</span>
{this.props.children}
</div>
);
}
});


This should be rendering <span>Testing Text</span> before every child. But it is not. What am I doing wrong?



My end goal is to make my options display various data like this:
enter


More From » reactjs

 Answers
23

The property is optionComponent not optionsComponent as you've written.


[#61363] Wednesday, July 13, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anikas

Total Points: 258
Total Questions: 102
Total Answers: 95

Location: Monaco
Member since Sun, Jan 16, 2022
2 Years ago
anikas questions
;