GithubHelp home page GithubHelp logo

Comments (3)

alexkirsz avatar alexkirsz commented on June 29, 2024

Calling any mutator method on the helper will produce a "change" event and the state of the store will change with a new searchParameters.

Calling .search() will also update state.searching from false to true, then update the state again once results have been retrieved.

Every state change will result in the mapStateToProps function of all connected components to be called. Simply calling search on componentDidMount will thus result in three calls: one on init, one once .search() has been called, and one once results have been retrieved.

Thankfully, we implement a shouldComponentUpdate hook on connected component that ensures that they will only re-render the underlying component when they receive new props or when the result of mapStateToProps has shallowly changed.

If you want to decrease the number of calls to mapStateToProps, try to decrease your state mutations. For instance, by using .getState()/.setState(newState) and manipulating the SearchParameters directly.

from react-algoliasearch-helper.

vvo avatar vvo commented on June 29, 2024

Hey @harshmaur, we have an alpha release of react-instantsearch, if you want to be part of it, send me an email to [email protected] I will follow up

from react-algoliasearch-helper.

harshmaur avatar harshmaur commented on June 29, 2024

@alexandremeunier I see. You are right.

In my componentDidMount I have been doing this.

helper.addFacetRefinement a few times which caused more rerenders.

So now instead of doing that I am directly modifying the searchParameters object and using .setState like this.

    const {helper} = this.props;
    const {category_slug = "", brand_slug = ""} = this.props.params;
    const partialState = url.getStateFromQueryString(document.location.search.slice(1));
    const state = helper.getState();

    if (_.isEmpty(partialState)){
      // happens on pages like http://localhost:3000/f/winter-wear/kanvin
      // where we dont have params like ?q=&dFR[store_name][0]=SNAPDEAL&fR[brand_slug][0]=kanvin&fR[category_slug][0]=winter-wear&fR[instock][0]=1

      _.assign(partialState, {facetsRefinements: {brand_slug: [brand_slug], category_slug: [category_slug], instock:[1] }});

      // handling issues where slugs are not present, example on search page


    }

    const updatedState = state.setQueryParameters(partialState);
    helper.setState(updatedState);


    helper.search();

I am still not sure if I did it properly, it seems to work though. Please advise.

from react-algoliasearch-helper.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.