You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**React Query External Sync** is a dynamic tool for managing React Query state outside the usual confines of React Query Dev Tools. Ideal for React projects, it offers a live state management solution that's accessible to both developers, qa and non-technical team members.
@@ -13,26 +36,35 @@
13
36
-**Continuous Evolution**: Built with expansion in mind, expect regular feature updates driven by community feedback and the evolving needs of modern development workflows.
14
37
-**Enhanced Manipulation**: Future updates will introduce capabilities for precise state adjustments, such as directly inserting complete objects or arrays, object duplication, simultaneous state syncing across web, Android, and iOS and persistent state overrides, allowing values for specific data to remain until manually reverted.
15
38
16
-
## Getting Started
39
+
<hr>
40
+
41
+
## Prerequisites
17
42
18
-
### Prerequisites
43
+
### Client Application
19
44
20
-
#### Client Application:
21
45
- React version 18 or above.
22
46
- React Query version 5.17.19 or above.
23
47
24
-
#### Socket IO Server:
48
+
### Socket IO Server
49
+
25
50
- Socket.io version 4.7.4 or above.
26
51
27
-
### Installation
52
+
### Devtool Website
53
+
54
+
- Any react.js ready server (vite, rca, ...)
55
+
56
+
## Installation
28
57
29
-
Install the package using npm by running the following command in your client project directory:
58
+
### Client
59
+
60
+
#### 1. Install the package
30
61
31
62
```bash
32
63
npm install react-query-external-sync
33
64
```
34
65
35
-
## Usage
66
+
#### 2. Connect your react-query to the socket
67
+
36
68
- Import the useAllQueries hook and utilize it within your client application to enable real-time synchronization with the external dashboard.
-**query**: Contains user information for identifying and managing connections in the dashboard.
53
86
-**queryClient**: Your application's React Query client instance.
54
87
-**socketURL**: The URL where your Socket.io server is hosted.
55
88
56
-
### Connecting to the Server
57
-
58
-
Utilize the connect function to initiate a connection with the socket server. Monitor the connection status using isConnected.
59
-
60
-
### Disconnecting from the Server
89
+
#### 3. Usages
61
90
62
-
Terminate the connection to the socket server by invoking the disconnect function.
63
-
64
-
### Accessing Queries
65
-
66
-
The queries property grants access to the synchronized query data, facilitating debugging and state management.
91
+
-`.connect()`: initiate a connection with the socket server
92
+
-`.disconnect()`: terminate the connection to the socket server by invoking the disconnect function
93
+
-`.isConnected`: monitor the connection status
67
94
68
95
### Socket IO Server
69
96
70
-
Run the following command in your Node server directory:
97
+
#### 1. Install the package
71
98
72
99
```bash
73
100
npm install react-query-external-dash
74
101
```
75
102
76
-
##Socket IO Setup:
103
+
#### 2. Setup Socket IO
77
104
78
-
- After setting up your Socket.io server, integrate the socketHandle function to manage incoming and outgoing messages related to query state synchronization.
105
+
- After setting up your Socket.io server, integrate the socketHandle function to manage incoming and outgoing messages related to query state synchronization.
If you don't want to setup both Socket.IO + Dedicated React.js server to monitor your app, a Docker image is available to launch those both services at once, with custom ports and CORS urls.
110
156
111
-
##React Query Dev Tools Integration:
157
+
### 1. Image link
112
158
113
-
- Incorporate the ExternalDevTools component within your server-side dashboard to display and interact with the synchronized React Query states.
-`DT_PORT`: Port for the Vite server to access your devtool
165
+
-`CORS_ORIGINS`: String to specify authorized url's for CORS in form of: "url1,url2,url3,..." (separate with coma without spaces). **Note that the devtool url is automaticly included in the CORS Policy.**
166
+
167
+
### 3. Docker Compose example
117
168
118
-
<ExternalDevTools
119
-
query={{
120
-
clientType:"server",
121
-
username:"Admin",
122
-
userType:"admin",
123
-
}}
124
-
socketURL="http://localhost:4000"// Use local ip if testing localy for Android ie http://192.168.4.21:4000
125
-
/>
169
+
- You'll also need to open both ports to use this image. We suggest to define those in environment variables.
0 commit comments