reactjs / react-autocomplete

WAI-ARIA compliant React autocomplete (combobox) component
MIT License
2.17k stars 532 forks source link

Warning: React.createElement: type is invalid #322

Closed yzaroui closed 6 years ago

yzaroui commented 6 years ago

I am trying the examples (copy/paste) before using the comp in my project but I always get an error : Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. I import it:

import Autocomplete from 'react-autocomplete';

then in render I return:

       <Autocomplete
          value={this.state.value}
          wrapperStyle={{ position: 'relative', display: 'inline-block' }}
          items={['a', 'b', 'c']}
          getItemValue={(item) => item}
          onChange={(event, value) => this.setState({ value })}
          onSelect={value => this.setState({ value })}
          renderMenu={children => (
            <div className="menu">
              {children}
            </div>
          )}
          renderItem={(item, isHighlighted) => (
            <div
              className={'item ' + isHighlighted ? 'item-highlighted' : ''}
              key={item}
            >{item}</div>
          )}
        />

Any idea?

yzaroui commented 6 years ago

Ok, this is due to the use of Typescript. Solved in issue #179.

dyesseyumba commented 6 years ago

I had the same issue. It works with import * as Autocomplete from 'react-autocomplete';