DEV Community

Xuan
Xuan

Posted on • Edited on

2 2 2 2 2

Build a Single Source of Truth by Using Daxus!

I'm excited to introduce Daxus I've developed to the community. In this article, I would like to simply share with everyone the motivation behind creating Daxus.

First of all, Daxus is a server state management package that make developer have full control over their data such that they can build a single source of truth by themselves.

Someone may ask: why don't you just use React Query or SWR?

In my company, we use redux with async thunk to manage the server state and implement single source of truth by ourselves. Take post as example, suppose there are two lists contain the post with the same id. This post share the same reference in the redux. That is, if the user update this post, the two posts will update simultaneously, and we don't need to make an extra request to refetch the whole post lists.

React Query encourages us invalidate the query if we have some data updated, which means that we need to refetch the whole list. However, refetch the two list just because we update a single post seems wasteful. We hope that we don't need to refetch the lists, but the same post in the both list should update also.

That is why I develope Daxus. You can find more details about the motivation in the readme also. Feel free to see it. https://github.com/jason89521/daxus#development-motivation

If you find this project interesting, also welcome to give it a star. It would be a tremendous encouragement to me. At the same time, I also hope that I can persuade my colleagues to adopt Daxus to our codebase. Thanks for your reading!

There is a question that I'm often asked:

Q: Why don't you just use queryClient.setQueryData?
A: In the pratical cases, we have not only two lists of the posts. If we consider update all these lists, it may be a disaster. Someone may ask, how about queryClient.setQueriesData? The answer is that the type is too dynamic. For more information, you can read this article.

If you have any question, I recommend read the motivation first. It provide more detail of why I want to develope Daxus. Thanks for reading!

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (1)

Collapse
 
jason89521 profile image
Xuan

Daxus is still in its early stage. If you find any bugs or have any problems, feel free to open an issue.

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay