How to use the react-instantsearch-dom.connectStateResults function in react-instantsearch-dom

To help you get started, we’ve selected a few react-instantsearch-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github janosh / janosh.io / src / components / Search / index.js View on Github external
import algoliasearch from 'algoliasearch/lite'
import React, { createRef, useMemo, useState } from 'react'
import { connectStateResults, Index, InstantSearch } from 'react-instantsearch-dom'
import { useOnClickOutside } from 'hooks'
import Hits from './Hits'
import Input from './Input'
import { HitsWrapper, PoweredBy, Root } from './styles'

const Results = connectStateResults(
  ({ searching, searchState: state, searchResults: res }) =>
    (searching &amp;&amp; <div>Searching...</div>) ||
    (res &amp;&amp; res.nbHits === 0 &amp;&amp; <div>No results for '{state.query}'</div>)
)

const Stats = connectStateResults(
  ({ searchResults: res }) =&gt;
    res &amp;&amp; res.nbHits &gt; 0 &amp;&amp; `${res.nbHits} result${res.nbHits &gt; 1 ? `s` : ``}`
)

export default function Search({ indices, collapse = true, hitsAsGrid }) {
  const ref = createRef()
  const [query, setQuery] = useState(``)
  const [focus, setFocus] = useState(false)
  const appId = process.env.GATSBY_ALGOLIA_APP_ID
  const searchKey = process.env.GATSBY_ALGOLIA_SEARCH_KEY
  // useMemo prevents the searchClient from being recreated on every render.
  // Avoids unnecessary XHR requests (see https://tinyurl.com/yyj93r2s).
  const searchClient = useMemo(() =&gt; algoliasearch(appId, searchKey), [
    appId,
    searchKey,
  ])
github pmt-mcpe-fun / website / components / PoggitSearch.jsx View on Github external
};
}

const SearchBox = ({ currentRefinement, refine }) =&gt; (
   refine(event.currentTarget.value)}
  /&gt;
);

const CustomSearchBox = connectSearchBox(SearchBox);

const Content = connectStateResults(
  ({ searchState, searchResults }) =&gt;
    searchResults &amp;&amp; searchResults.nbHits !== 0
      ? null
      : <div>
          No plugins were found matching <em>{searchState.query}</em>
        </div>
);


const Hit = ({ hit }) =&gt; {
  if (hit.api &amp;&amp; hit.api.length) {
    if (SemverJS.split(hit.api[0].from).major == '3') {
      return (
        
          
            <a href="{`https://poggit.pmmp.io/p/${hit.project_name}`}"></a>
github ChilliCream / hotchocolate / website / src / components / misc / search.tsx View on Github external
}

const SearchBox = connectSearchBox(
  ({ currentRefinement, onFocus, refine }) =&gt; (
     refine(e.target.value)}
      onFocus={onFocus}
    /&gt;
  )
);

const Results = connectStateResults((comp) =&gt;
  comp.searchResults &amp;&amp; comp.searchResults.nbHits &gt; 0
    ? (comp.children as any)
    : (`No results for '${comp.searchState.query}'` as any)
);

const Stats = connectStateResults(
  (comp) =&gt;
    comp.searchResults &amp;&amp;
    comp.searchResults.nbHits &gt; 0 &amp;&amp;
    (`${comp.searchResults.nbHits} result${
      comp.searchResults.nbHits &gt; 1 ? `s` : ``
    }` as any)
);

const DocHit = (siteUrl: string, clickHandler: () =&gt; void) =&gt; ({
  hit,
github wildbit / smtp-field-manual / src / components / search / index.js View on Github external
Index,
  Hits,
  connectStateResults,
} from 'react-instantsearch-dom'
import algoliasearch from 'algoliasearch/lite'
import cn from 'classnames'
import { Algolia } from 'styled-icons/fa-brands/Algolia'

import Input from './input'
import * as hitComps from './hitComps'

const IndexResults = connectStateResults(({ searchResults, children }) =&gt;
  searchResults &amp;&amp; searchResults.nbHits !== 0 ? children : null
)

const AllResults = connectStateResults(
  ({ allSearchResults, searching, children }) =&gt; {
    const hasResults =
      allSearchResults &amp;&amp;
      Object.values(allSearchResults).some(results =&gt; results.nbHits &gt; 0)

    return !hasResults ? (
      <div>
        {searching ? (
          <div>
            <h5 aria-hidden="">
            <p>Searching the catacombs...</p>
          </h5></div>
        ) : (
          <div>
            <h5 aria-hidden="">
            <p>Couldn’t find any results!</p></h5></div></div>
github algolia / react-instantsearch / stories / Conditional.stories.js View on Github external
.add('NoLoading/HasQuery', () =&gt; {
    const Content = connectStateResults(({ searching }) =&gt;
      searching ? <div>searching</div> : <div>No searching</div>
    );
    return (
      
        <content>
      </content>
    );
  });
github janosh / janosh.io / src / components / Search / index.js View on Github external
import algoliasearch from 'algoliasearch/lite'
import React, { createRef, useMemo, useState } from 'react'
import { connectStateResults, Index, InstantSearch } from 'react-instantsearch-dom'
import { useOnClickOutside } from 'hooks'
import Hits from './Hits'
import Input from './Input'
import { HitsWrapper, PoweredBy, Root } from './styles'

const Results = connectStateResults(
  ({ searching, searchState: state, searchResults: res }) =&gt;
    (searching &amp;&amp; <div>Searching...</div>) ||
    (res &amp;&amp; res.nbHits === 0 &amp;&amp; <div>No results for '{state.query}'</div>)
)

const Stats = connectStateResults(
  ({ searchResults: res }) =&gt;
    res &amp;&amp; res.nbHits &gt; 0 &amp;&amp; `${res.nbHits} result${res.nbHits &gt; 1 ? `s` : ``}`
)

export default function Search({ indices, collapse = true, hitsAsGrid }) {
  const ref = createRef()
  const [query, setQuery] = useState(``)
  const [focus, setFocus] = useState(false)
  const appId = process.env.GATSBY_ALGOLIA_APP_ID
  const searchKey = process.env.GATSBY_ALGOLIA_SEARCH_KEY
github algolia / react-instantsearch / examples / default-theme / App.js View on Github external
<div>
          
        </div>
        <div>
          
        </div>
        <div>
          <div>{icons}</div>
          <div>${hit.price}</div>
        </div>
      
    
  );
};

const CustomResults = connectStateResults(({ searchState, searchResults }) =&gt; (
  <div>
    <section>
      
      <div>
        <label>Sort by</label>
        
      </div>
    </section>
</div>
github algolia / react-instantsearch / examples / e-commerce / widgets / NoResults.js View on Github external
fill="#000"
                    fillRule="nonzero"
                    d="M8.26 2.75a3.896 3.896 0 1 0 1.102 3.262l.007-.056a.49.49 0 0 1 .485-.456c.253 0 .451.206.437.457 0 0 .012-.109-.006.061a4.813 4.813 0 1 1-1.348-3.887v-.987a.458.458 0 1 1 .917.002v2.062a.459.459 0 0 1-.459.459H7.334a.458.458 0 1 1-.002-.917h.928z"
                  /&gt;
                
              
              Clear filters
            
          ),
        }}
      /&gt;
    
  );
};

export default connectStateResults(NoResults);