Using React Query in ClojureScript
react-query is one of those libraries for React that makes it simpler to manage remote state, the library is a perfect fit when your app consumes REST API.
React Query is written in modern JavaScript, using various language features including private field, which is something that Google Closure Compiler doesn't support, unfortunately. Since ClojureScript relies on Closure Compiler to optimise and bundle generated JavaScript, this becomes quite annoying problem.
In NPM/Node ecosystem it's possible to encapsulate JS modules internal to a package and whitelist only those modules that library author decided to export, see "exports" field docs. React Query v5 includes precompiled sources where private fields syntax doesn't exist, but those modules are shielded by "exports" setting in package.json
In shadow-cljs starting from v2.28.19 it's now possible to bypass "exports" setting and consume the library without introducing additional build step. The following shadow-cljs.edn config enables bypass option and creates aliases for packages to point requires to precompiled sources.
{:js-options {:exports-bypass true
:resolve {"@tanstack/react-query" {:target :npm
:require "@tanstack/react-query/build/legacy/index.js"}
"@tanstack/query-core" {:target :npm
:require "@tanstack/query-core/build/legacy/index.js"}}}}