cantierecreativo/redux-bees

Query using already fetched data from redux store

Opened this issue · 3 comments

I my our setup we want the query HOC to fetch the data, save it in the redux store (which it obviously does), but reuse that data, when its component is mounted for a second time, and avoid that extra http call.
What would be a good way of achieving this?

We have a similar issue. We are using getRelationship as follows:

@query('message', api.getMessage, (perform, props) => (
    perform({ threadId: props.match.params.threadId, messageId: props.messageId, include: 'user' })
))

@connect((state, props) => {
    return (
        {
            user: props.message && getRelationship(state, props.message, 'user')
        }
    )
})

We would expect that once the related resources (users) are loaded, it should not require another api call at least for a specified amount of time. What we are finding is that each time we load the same message list, it makes all the individual user api calls as well for each message.

benjy commented

I started off working around this by having the data fetched in a parent component that isn't unmounted and then passed through as props, that doesn't very well at all though.

My current solution is to have query check if the request has started before calling fetch: #59

Anybody home here? @benjy your PR seems to work well.