I am using es6 classes and react-select to create a dropdown menu and want to replace the component for the react-select menu icon. My methods are static, so I expect to be able to use them by calling them using the class name, in this case CustomSelectDropDown, but I keep getting this error:
React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: . Did you accidentally export a JSX literal instead of a component? in Select (created by StateManager)
My code looks like this:
import React, { Component } from 'react';
import Select, { components } from 'react-select';
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCaretDown } from "@fortawesome/free-solid-svg-icons";
import { library } from "@fortawesome/fontawesome-svg-core";
library.add(faCaretDown);
export class CustomSelectDropDown extends Component {
static Placeholder(props) {
return <components.Placeholder {...props} />;
}
static CaretDownIcon () {
return <FontAwesomeIcon icon="caret-down" />;
};
static DropdownIndicator(props) {
return (
<components.DropdownIndicator {...props}>
{ this.CaretDownIcon() }
</components.DropdownIndicator>
);
};
render() {
return (
<div className="customSelect" id={this.props.idName}>
<div className="fb--w60">
<Select
...
components={{
Placeholder: CustomSelectDropDown.Placeholder(),
DropdownIndicator: CustomSelectDropDown.DropdownIndicator() }}
...
/>
</div>
</div>
);
}
}
export default CustomSelectDropDown;
What I am doing incorrectly? I thought this was the proper way of using static methods.
If I try to change the DropdownIndicator's call this.CaretDownIcon() to CustomSelectDropDown.CaretDownIcon() instead, then I get the following a different error, shown below, but I think using this.CaretDownIcon() should be the right way.
Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of
Select.
Perhaps this has to do more with react-select than JS/reactjs/es6?