-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation (cookbook): Advanced Loading Patterns #5
Comments
Yeah this is a caveat with using URLs as the "cache key" and not basing off entities. A problem that GraphQL clients inherently do not have. What we sometimes do, which I think is similar to what you're describing, is check to see if we already have the entity we need from the entities reducer, and then return For example: const DashboardContainer = connectRequest((props) => {
if (dashboard) {
return {
url: `/api/dashboard/${props.dashboardId}`,
update: { ... },
};
} else {
// already have dashboard (perhaps from a different query/URL), do not make an unnecessary request
return null;
}
});
const mapStateToProps = (state, props) => {
const dashboard = selectors.getDashboard(props.dashboardId);
return {
dashboard,
};
}; |
Yup that code snippet embodies what I meant: |
@ryanashcraft Trying out this approach I'm getting warnings from redux-query stating it's attempting to cancel a request that is not in-flight. This is caused by the query being nulled as soon as Probably not an issue at all but the warnings are slightly distracting:
Code: const mapStateToProps = (state, { id }) => ({
page: getPageById(state, id),
})
const mapPropsToQuery = ({ id, page }) => (
!page && createPageQuery({ id }))
)
compose(
connect(mapStateToProps),
connectRequest(mapPropsToQuery),
) |
@simenbrekken This should be fixed with 2.0. Closing this issue. If someone would like to contribute more demos for the redux-query site that demonstrates these patterns, feel free to open up a PR. All I ask is that the demo is smallish and matches the style of the current demos. |
upgrade dist to 3.3.0
Our app can load the same entity in two ways: by its ID, or by loading a list with that entity.
I want to avoid loading the single entity after having loaded the list view, even though redux-query will see them as different routes. Redux-query cannot know the relationships between my routes and adjust its cache strategy for them - that's fine.
My solution is simple:
I'm using mapState to determine whether or not a component has all the data it needs to render, which it then lets redux-query and the component know by attaching a
loading
prop.My connect request
mapPropsToConfig
then only fetches if loading is true.This reduces redundant requests, but does allow a few cases where data can still be fetched (in the case of coordinating loading many different entity types from singly typed routes, á la REST, the order the requests come back in can effect rendering during the app's bootstrapping phase).
The text was updated successfully, but these errors were encountered: