Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. Error:Error:line (104)Cannot create `Select` element because array type [1] is incompatible with `OptionType` [2] in the first argument of property `onChange`.
  2. Error:Error:line (104)Cannot create `Select` element because array type [1] is incompatible with null [2] in the first argument of property `onChange`.
  3. Error:Error:line (104)Cannot create `Select` element because array type [1] is incompatible with undefined [2] in the first argument of property `onChange`.
  4.  
  5. // @flow
  6. import * as React from 'react';
  7. import Select from 'react-select';
  8.  
  9. type LabelValueObject = Object & {
  10. value: string,
  11. label: string
  12. }
  13.  
  14. type State = {
  15. options: LabelValueObject[],
  16. selectedOptions: LabelValueObject[],
  17. }
  18.  
  19. export class ServiceDropdown extends React.Component<Props, State> {
  20. constructor(props: Props) {
  21. super(props);
  22.  
  23. this.state = {
  24. options: [],
  25. selectedOptions: null,
  26. };
  27. }
  28.  
  29. handleChange = (selectedOptions: LabelValueObject[]): void => {
  30. this.setState({ selectedOptions });
  31. };
  32.  
  33. render() {
  34. const { selectedOptions } = this.state;
  35. return (
  36. <>
  37. <Select
  38. isMulti
  39. isSearchable
  40. onChange={this.handleChange} <=== flow error
  41. value={selectedOptions}
  42. options={this.state.options}
  43. />
  44. </>
  45. );
  46. }
  47. }
  48.  
  49. export default ServiceDropdown;
  50.  
  51. onChange: (ValueType, ActionMeta) => void,
  52.  
  53. type ValueType = OptionType | OptionsType | null | void
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement