How to use the react-instantsearch/connectors.connectHighlight function in react-instantsearch

To help you get started, we’ve selected a few react-instantsearch 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 joshwcomeau / guppy / src / components / CustomHighlight / CustomHighlight.js View on Github external
// Run the DOMParser on each of the parts of text
    const unescaped = safeEscapeString(part.value);

    // If the text is highlighted, wrap in <mark> for the highlight
    // Otherwise just render the part in a <span>
    return part.isHighlighted ? (
      <mark>
        {unescaped}
      </mark>
    ) : (
      <span>{unescaped}</span>
    );
  });
};

export default connectHighlight(CustomHighlight);
</span></mark>
github dlbnco / tripby.org / app / components / Search / index.js View on Github external
<input> { this.searchInput = input }}
            type="text"
            className="form-control form-control-lg"
            value={this.props.currentRefinement} //eslint-disable-line
            onChange={(e) =&gt; this.props.refine(e.target.value)} //eslint-disable-line
          /&gt;
        
      
    )
  }
}

const ConnectedSearchBox = connectSearchBox(MySearchBox)

const CustomHighlight = connectHighlight(
  ({ highlight, attribute, hit }) =&gt; {
    const parsedHit = highlight({
      attribute,
      hit,
      highlightProperty: '_highlightResult',
    })
    const highlightedHits = parsedHit.map((part) =&gt; {
      if (part.isHighlighted) return <mark>{part.value}</mark>
      return part.value
    })
    return <div>{highlightedHits}</div>
  }
)

const Hit = ({ hit }) =&gt; ( //eslint-disable-line
github jscoach / client / src / Highlight.js View on Github external
import React from "react";
import { connectHighlight } from "react-instantsearch/connectors";

const Highlight = connectHighlight(({ highlight, attributeName, hit, highlightProperty }) =&gt; {
  const parsedHit = highlight({
    attributeName,
    hit,
    highlightProperty: "_highlightResult",
  });
  const highlightedHits = parsedHit.map(part =&gt; {
    if (part.isHighlighted) return `<mark>${part.value}</mark>`;
    return part.value;
  });
  return <span>;
});

export default Highlight;
</span>