algolia.configure.js

    0

    0

    YusifHasanov

    The following code initializes an Algolia search using the client object and passes in the appid, apikey values from the API call. Next, the index object is initialized, and the send() and get() methods are invoked. The update() method is used to modify the index's partialUpdateObjects() method. The delete() method is used to delete an object from the index.

    Library: react

    import algoliasearch from 'algoliasearch';
    
    const client = algoliasearch('blablablaappid', 'blablablaapikey');
    const index = client.initIndex('codehub');
    
    export const algolia = {
      send: (data) => {
        index
          .saveObject(data)
          .then((response) => {
            console.log(response);
          })
          .catch((err) => console.log(err));
      },
    
      get :(search)=>{
        index.search(search).then(({ hits }) => {
            setUsers(hits);
          });
      },
      
      update : (data) =>{
        index.partialUpdateObjects(data).then((response) => {
            console.log(response);
          }).catch((err) => console.log(err));
      },
    
      delete : (id) =>{
        index.deleteObject(id).then(() => {});     
      }
    };
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.