question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AsyncTypeahead is not showing results

See original GitHub issue

Version

3.0.3

Steps to reproduce

I am creating an async typeahead that searches for clients using our API’s advanced query filtering that matches on multiple attributes.

          <AsyncTypeahead
            placeholder="Search for a client by name, address, phone, etc."
            onSearch={this.onSearch}
            isLoading={this.state.isSearchLoading}
            options={this.state.options}
            renderMenuItemChildren={(c, props) => {
              console.log(c);
              return <div key={c.id}>{c.searchPreviewStr}</div>;
            }}/>

And here is my onSearch method:

  onSearch = async (query: string) => {
    this.setState({isSearchLoading: true});
    const { data }: any = await getApolloClient().query({
      query: gql`
        query ($searchStr: String!) {
          allClients(first: 10, search: $searchStr) {
            edges { node { ${CLIENT_WITH_CONTACT_NAME_GQL_QUERY_FIELDS} }}
          }
        }
      `,
      variables: {
        searchStr: query
      }
    });

    this.setState({
      options: data.allClients.edges.map((attrs: any) => new Client(attrs.node)),
      isSearchLoading: false
    });
  };

onSearch issues an async query and sets the state. I’m confident it’s setting the state properly because I can console.log this.state.options in the render method, and I see the results.

Expected Behavior

It should display my results exactly using my custom renderMenuItemChildren method without any further filtering.

Actual Behavior

It appears to be trying to do some extra filtering using the default filterBy attribute.

The typeahead shows “No results found”, and the JS console displays this error: Warning: [react-bootstrap-typeahead] Fields passed to filterBy should have string values. Value will be converted to a string; results may be unexpected..

Notice I have a console.log in my renderMenuItemChildren. This never gets called, so the error happens before the menu attempts rendering.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
lehresmancommented, Apr 17, 2018

Yep, thanks. That fixed it. I jumped straight to the AsyncTypeahead section of the docs and skipped the Data section.

1reaction
ericgiocommented, Apr 17, 2018

@lehresman: What’s the shape of the data in this.state.options? It looks like you’re possibly creating some custom objects and the typeahead may be getting something it doesn’t expect.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AsyncTypeahead results are not being displayed on screen
The UI simple displays a No matches found message on the screen. I get a warning message on the console saying Warning: [react-bootstrap- ......
Read more >
Asynctypeahead Results Are Not Being Displayed ... - ADocLib
Asynctypeahead Results Are Not Being Displayed On Screen. This directive will show a dropdown if there are less than 25 items to choose...
Read more >
Clearing inputText using react-bootstrap-typeahead when ...
score :0. I was using AsyncTypeAhead and had to do the following. var asyncTypeAhead = typeAhead as AsyncTypeahead; asyncTypeAhead.getInstance().clear();.
Read more >
react-bootstrap-typeahead - UNPKG
Invoked when the pagination menu item is clicked. Receives an event as the first argument and the number of shown results as the...
Read more >
How to use AsyncTypeahead in react-bootstrap-typeahead
Best JavaScript code snippets using react-bootstrap-typeahead.AsyncTypeahead(Showing top 2 results out of 315) · src/Search.js/Search · src/components/Commons/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found