how to use comparison?
Closed this issue · 1 comments
sleungcy commented
comparison: Any, optional. If provided, a new request is not made if the comparison value between dispatch calls is the same.
i want the app to only do an initial fetch when the component first load and ignore all subsequent updates, and I am wonder if the comparison flag can be used for this purpose? What do I pass into comparison? It says it can accept any value type? Can you please provide an example?
Thanks!
hirviid commented
Hi, indeed, comparison could be used for that. Just give it a unique value (string or number).
Another option would be to check if the state already has the data, and only execute the dispatch method if the state doesn't have the value yet:
class MyComponent extends React.Component {
componentWillMount() {
if (!this.props.exampleFetch.value) {
this.props.dispatchExampleGet();
}
}
// ...
}
reduxFetch([
{
resource: 'example',
request: {
url: '/api/example'
}
}
])(MyComponent);