npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-algolia

v1.3.1

Published

React algolia library

Downloads

557

Readme

React Algolia

Config

import { AlgoliaProvider, defineAlgoliaApp } from 'react-algolia';

const App = () => (
  <AlgoliaProvider
    applications={[
      defineAlgoliaApp(
        APP_APPLICATION_ID,
        API_KEY,
        INDEX_NAME
      ),
      defineAlgoliaApp(
        ANOTHER_APP_APPLICATION_ID,
        ANOTHER_API_KEY,
        ANOTHER_INDEX_NAME
      )
    ]}
  >
    <Main />
  </AlgoliaProvider>
)

Usage

get index

import { useAlgoliaIndex } from 'react-algolia';

const GetIndexExample = () => {
  const index = useAlgoliaIndex({
    indexName: 'index-name'
  });

  return (
    <div>
      Get Index Example
      <button onClick={() => {
        if (index) {
          console.log('got index instance', index)
        }
      }}>Get Index</button>
    </div>
  )
}

get object

import { useAlgoliaGetObject } from 'react-algolia';

const GetObjectExample = () => {
  const { object, loading, error, index } = useAlgoliaGetObject({
    indexName: 'index-name',
    objectId: 'algolia-object-id',
    fields: ['objectID', 'name']
  });

  return (
    <div>Get Object Example</div>
  );
};

lazy get object

import { useAlgoliaLazyGetObject } from 'react-algolia';

const LazyGetObjectExample = () => {
  const [execute, { object, loading, error, index }] = useAlgoliaLazyGetObject({
    indexName: 'index-name',
    objectId: 'algolia-object-id',
    fields: ['objectID', 'name']
  });

  return (
    <div>
      Lazy Get Object Example
      <button onClick={() => execute()}>Get Object</button>
    </div>
  );
};

get objects

import { useAlgoliaGetObjects } from 'react-algolia';

const GetObjectsExample = () => {
  const { objects, loading, error, index } = useAlgoliaGetObjects({
    indexName: 'index-name',
    objectIds: ['algolia-object-ids'],
    fields: ['objectID', 'name']
  });

  return (
    <div>Get Objects Example</div>
  );
};

lazy get objects

import { useAlgoliaLazyGetObjects } from 'react-algolia';

const LazyGetObjectsExample = () => {
  const [execute, { objects, loading, error, index }] = useAlgoliaLazyGetObjects({
    indexName: 'index-name',
    objectIds: ['algolia-object-ids'],
    fields: ['objectID', 'name']
  });

  return (
    <div>
      Lazy Get Objects Example
      <button onClick={() => execute()}>Lazy Get Objects</button>
    </div>
  );
};

search

import { useAlgoliaSearch } from 'react-algolia';

const SearchExample = () => {
  const {
    searchResults,
    loading,
    error,
    index
  } = useAlgoliaSearch({
    indexName: 'index-name',
    query: 'keyword', // query string to search
    page: 0, // page number starts from  0
    hitsPerPage: 10, // page size: default to be 10
    filters: 'deleted:false' // filters,
    delay: 300 // debounce ms between query value changes,
    key: 0 // query key, pass a new value will invalidate cache of this index and initiate a new search
  });

  return (
    <div>Search Example</div>
  );
};

lazy search

import { useAlgoliaLazySearch } from 'react-algolia';

const LazySearchExample = () => {
  const [
    execute,
    { searchResults, loading, error, index }
  ] = useAlgoliaLazySearch({
    indexName: 'index-name',
    query: 'keyword', // query string to search
    page: 0, // page number starts from  0
    hitsPerPage: 10, // page size: default to be 10
    filters: 'deleted:false' // filters,
    delay: 300 // debounce ms between query value changes,
    key: 0 // query key, pass a new value will invalidate cache of this index and initiate a new search
  });

  return (
    <div>
      Lazy Search Example
      <button onClick={() => execute()}>Search</button>
    </div>
  );
};

browse index

import { useAlgoliaBrowseAll } from 'react-algolia';

const BrowseExample = () => {
  // browse the whole index (not limited to 1000 objects per request)
  const { browse } = useAlgoliaBrowseAll({
    indexName: 'index-name',
    filters: 'deleted:false'
  });

  return (
    <div>
      Browse Example
      <button onClick={() => browse()}>Browse</button>
    </div>
  );
};