[Feedback/Feature Request]: Allow using state selectors without specifying the args
Closed this issue · 1 comments
Hi!
I recently started using this library and so far I've been very impressed. I have run into a bit of an issue though that I think either I'm doing something I'm not supposed to, or this is a case where it could be made easier to use.
Per the documentation, if I perform a fetch such as dispatch(api.getPosts({ is_active: true }))
, I can retrieve the results in my mapStateToProps
function by writing getRequestInfo(state, api.getPosts, [{ is_active: true }])
.
That works fine, however, I also want to put the search criteria into my query string so the search persists if the page gets refreshed. After a round trip through the query string, the parameter becomes { is_active: "true" }
and it fails to match the request that's already in the redux store because "true" !== true
. I could transform any non-string query string parameters, but that sounds like a nightmare to have to maintain.
I'd like to see an option to fetch a request using a given name dispatch(api.getPosts({ is_active: true }, { requestId: "search" }))
and then retrieve it using the name instead of the args getRequestInfo(state, api.getPosts, { requestId: "search" })
. Does that sound feasible?
As a hack, I was able to approximate this behavior by adding a toJSON
override to my query object: { is_active: "true", toJSON() { return "search" } }
and it worked, I could retrieve it with getRequestInfo(state, api.getPosts, ["search"])
.
Doesn't seem like a lot of interest in this and I've already refactored the component in question to not be as brittle, so I'm closing this issue.