Comments (3)
Thanks for sharing, @rblakemesser.
from redux-query.
@ryanashcraft I've been thinking about something since I started working with redux-query
, which is described in the README as
a library for querying and managing network state in React/Redux applications.
If that's its scope, why does it impose its own entities reducer?
Don't take me wrong, I'm ok with redux-query
shipping an entity reducer for whoever wants to make use of it, but I'd love to be able to opt it out in a simple manner.
For now, what I'm doing is something like this:
const mapDispatchToProps = { actionCreator }
const mapPropsToQuery = (props) => ({
url: `api/todos`,
// gets dispatched as soon as the requests completes
transform: props.actionCreator,
update: {} // required by redux-query
})
const enhance = compose(
connect(void 0, mapDispatchToProps),
connectRequest(mapPropsToQuery)
)
export default enhance(Component)
Note that I'm using
trasnform
instead ofupdate
to have a more generic code, but it would work either way. #2 uses a similar approach.
Where actionCreator
is in charge of handling responses (normalize and store data, and potentially other stuff like handling pagination logic.) This enables me to work with my own reducers.
However, to roll back optimistic updates, I'd need to have my entities reducer react to the MUTATE_FAILURE
action. #9 (which was created by the same user as #2) proposes adding other callbacks which could help in dealing with this scenario.
Even if this was added I feel like the code for updating entities (optimistically and otherwise) is too coupled to your implementation of the entities reducer. Both this issue and #34 display how cumbersome it can be to use your own reducers.
I'd love to hear your thoughts on this :)
from redux-query.
@acontreras89 FYI the rollback
handler has been added in 2.0.
As far as it goes with the coupling between entities
reducer and the middleware – I don't have a better answer other than redux-query is opinionated in this way. Having this coupling keeps the overall API simpler for our use case where we want all of the network state in a single location.
from redux-query.
Related Issues (20)
- React redux v6 support? HOT 3
- Body is not being stringified and appended to the URL as query params. HOT 4
- Feature Request - Return data on repeated requests. HOT 3
- useRequest and useMutation not working property with custom middlewares HOT 6
- Feature Request - Add useRequests hooks HOT 5
- use options.header to re-memoize query configs HOT 8
- Accessing store in network interface
- useMutation error after Typescript update HOT 1
- Lazy loaded useMutation HOT 7
- Problem with useRequest HOT 2
- Feature request - Debounce HOT 3
- Testing redux-query HOT 1
- Can't use useRequest with Typescript HOT 5
- isPending Bug on useRequest HOT 4
- Mutation Promise chain setup HOT 3
- Problem with CRA code and the query middleware? HOT 1
- Question about where to put side effects HOT 5
- How can I clear all cached queries and fetch it all again after logout. HOT 1
- Handling errors HOT 1
- Need a code snippet on how to implement forceRequest
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 redux-query.