Comments (3)
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.
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.
@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)
- Usage with React Redux HOT 4
- Dynamically change helper configuration from inside the component HOT 6
- Make two separate queries in same Component HOT 23
- One query overrides the last (rather than adding to it...) HOT 1
- Pass data between components using URL HOT 9
- TypeError: Cannot read property 'shape' of undefined HOT 1
- Real Library™️
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-algoliasearch-helper.