inveniosoftware / react-searchkit

React component library for interacting with a REST API.
https://inveniosoftware.github.io/react-searchkit/
MIT License
78 stars 40 forks source link

ESSearchAPI is not a constructor #94

Closed hauph closed 4 years ago

hauph commented 4 years ago

Hello,

I followed this instruction to connect ElasticSearch to react-searchkit, and my configuration was as follow:

import { 
    ESSearchAPI,
    ReactSearchKit, 
    ResultsGrid, 
} from 'react-searchkit';

export default class FileLibrary extends React.Component<Props, State> {
   constructor(props:Props) {
       super(props);

       this.searchkit = new ESSearchAPI({
           url: `https://localhost:9200/my-index/_search`,
           timeout: 5000,
       });
   }
}

However, it did not succeed and instead I received the following error: index.js:120 Uncaught TypeError: react_searchkit__WEBPACK_IMPORTED_MODULE_16__.ESSearchAPI is not a constructor

Can anyone please tell my what I did wrong here? I would be truly grateful for any help.

hauph commented 4 years ago

I consoled the whole react-searchkit source in my app (I installed it via npm) and I saw an object module which includes ESSearchAPI, but when I consoled ESSearchAPI, it showed undefined.

I even checked the whole react-searchkit source code folder and I found ESSearchAPI is exported, so it should be ready to use. ESSearchAPI is existed, then why can't I call it out and use it on front-end?

This is just crazy!!

hauph commented 4 years ago

OMG I know what's wrong. In your documenation, you wrote:

const searchApi = new ESSearchAPI({
  url: 'https://my.es.backend.org/search/',
  timeout: 5000
});

class App extends Component {
  render() {
    return (
      <ReactSearchKit searchApi={searchApi}>
        ...
      </ReactSearchKit>
    )
  }
}

What's wrong here is it should be ESSearchApi, not ESSearchAPI. Just a typo but it has driven me crazy for 3 hours @@.

lnielsen commented 4 years ago

Thanks for reporting. I've fixed it in the docs now so others won't have the same problem.