@bluecopa/react 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # @bluecopa/reactjs
2
+
3
+ A React.js wrapper for TanStack React Query with Bluecopa core integration.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @bluecopa/reactjs @bluecopa/core @tanstack/react-query
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### 1. Setup the Provider
14
+
15
+ Wrap your app with the `BlueCopaQueryProvider`:
16
+
17
+ ```tsx
18
+ import React from 'react';
19
+ import { BlueCopaQueryProvider } from '@bluecopa/reactjs';
20
+ import { ApiClient } from '@bluecopa/core';
21
+
22
+ const apiClient = new ApiClient({
23
+ baseURL: 'https://api.example.com',
24
+ // other config options
25
+ });
26
+
27
+ function App() {
28
+ return (
29
+ <BlueCopaQueryProvider
30
+ config={{
31
+ apiClient,
32
+ defaultStaleTime: 5 * 60 * 1000, // 5 minutes
33
+ defaultCacheTime: 10 * 60 * 1000, // 10 minutes
34
+ enableDevtools: true,
35
+ }}
36
+ >
37
+ <YourAppComponents />
38
+ </BlueCopaQueryProvider>
39
+ );
40
+ }
41
+ ```
42
+
43
+ ### 2. Using Queries
44
+
45
+ ```tsx
46
+ import React from 'react';
47
+ import { useQuery } from '@bluecopa/reactjs';
48
+
49
+ function UserProfile({ userId }: { userId: string }) {
50
+ const { data, isLoading, error } = useQuery({
51
+ queryKey: {
52
+ scope: 'users',
53
+ endpoint: `/users/${userId}`,
54
+ },
55
+ staleTime: 5 * 60 * 1000,
56
+ });
57
+
58
+ if (isLoading) return <div>Loading...</div>;
59
+ if (error) return <div>Error: {error.message}</div>;
60
+
61
+ return <div>User: {data?.name}</div>;
62
+ }
63
+ ```
64
+
65
+ ### 3. Using Mutations
66
+
67
+ ```tsx
68
+ import React from 'react';
69
+ import { usePost, usePut } from '@bluecopa/reactjs';
70
+
71
+ function CreateUser() {
72
+ const createUser = usePost('/users', {
73
+ onSuccess: (data) => {
74
+ console.log('User created:', data);
75
+ },
76
+ onError: (error) => {
77
+ console.error('Failed to create user:', error);
78
+ },
79
+ });
80
+
81
+ const handleSubmit = (userData: any) => {
82
+ createUser.mutate(userData);
83
+ };
84
+
85
+ return (
86
+ <form onSubmit={handleSubmit}>
87
+ {/* form fields */}
88
+ <button
89
+ type="submit"
90
+ disabled={createUser.isPending}
91
+ >
92
+ {createUser.isPending ? 'Creating...' : 'Create User'}
93
+ </button>
94
+ </form>
95
+ );
96
+ }
97
+ ```
98
+
99
+ ### 4. Using Infinite Queries
100
+
101
+ ```tsx
102
+ import React from 'react';
103
+ import { useInfiniteQuery } from '@bluecopa/reactjs';
104
+
105
+ function UserList() {
106
+ const {
107
+ data,
108
+ fetchNextPage,
109
+ hasNextPage,
110
+ isFetchingNextPage,
111
+ isLoading,
112
+ } = useInfiniteQuery({
113
+ queryKey: {
114
+ scope: 'users',
115
+ endpoint: '/users',
116
+ params: { limit: 10 },
117
+ },
118
+ getNextPageParam: (lastPage) => lastPage.nextPage,
119
+ });
120
+
121
+ if (isLoading) return <div>Loading...</div>;
122
+
123
+ return (
124
+ <div>
125
+ {data?.pages.map((page, i) => (
126
+ <div key={i}>
127
+ {page.data.map((user: any) => (
128
+ <div key={user.id}>{user.name}</div>
129
+ ))}
130
+ </div>
131
+ ))}
132
+ {hasNextPage && (
133
+ <button
134
+ onClick={() => fetchNextPage()}
135
+ disabled={isFetchingNextPage}
136
+ >
137
+ {isFetchingNextPage ? 'Loading more...' : 'Load More'}
138
+ </button>
139
+ )}
140
+ </div>
141
+ );
142
+ }
143
+ ```
144
+
145
+ ## API Reference
146
+
147
+ ### BlueCopaQueryProvider
148
+
149
+ The main provider component that sets up React Query with Bluecopa core integration.
150
+
151
+ #### Props
152
+
153
+ - `config?: BlueCopaQueryConfig` - Configuration options
154
+
155
+ #### BlueCopaQueryConfig
156
+
157
+ ```typescript
158
+ interface BlueCopaQueryConfig {
159
+ apiClient?: ApiClient;
160
+ queryClient?: QueryClient;
161
+ defaultStaleTime?: number;
162
+ defaultCacheTime?: number;
163
+ defaultRetry?: number | boolean;
164
+ enableDevtools?: boolean;
165
+ }
166
+ ```
167
+
168
+ ### Hooks
169
+
170
+ #### useQuery
171
+
172
+ Enhanced version of TanStack's useQuery with Bluecopa integration.
173
+
174
+ #### useMutation, usePost, usePut, usePatch, useDelete
175
+
176
+ Enhanced mutation hooks with built-in HTTP method support.
177
+
178
+ #### useInfiniteQuery
179
+
180
+ Enhanced infinite query hook for pagination.
181
+
182
+ ## Development
183
+
184
+ ```bash
185
+ # Install dependencies
186
+ pnpm install
187
+
188
+ # Build the package
189
+ pnpm build
190
+
191
+ # Run in development mode (watch)
192
+ pnpm dev
193
+
194
+ # Run tests
195
+ pnpm test
196
+ ```
197
+
198
+ ## License
199
+
200
+ MIT
@@ -0,0 +1,33 @@
1
+ import { c, T as l, P as m, a as u, D as v, Q as i } from "./VREWMQAW-DGhbq4hm.js";
2
+ import { g as d, c as f, a as e } from "./index-bzN7KmNV.js";
3
+ var p = (a) => {
4
+ const [r, t] = c({
5
+ prefix: "TanstackQueryDevtools"
6
+ }), n = d(), s = f(() => {
7
+ const o = r.theme_preference || l;
8
+ return o !== "system" ? o : n();
9
+ });
10
+ return e(i.Provider, {
11
+ value: a,
12
+ get children() {
13
+ return e(m, {
14
+ localStore: r,
15
+ setLocalStore: t,
16
+ get children() {
17
+ return e(u.Provider, {
18
+ value: s,
19
+ get children() {
20
+ return e(v, {
21
+ localStore: r,
22
+ setLocalStore: t
23
+ });
24
+ }
25
+ });
26
+ }
27
+ });
28
+ }
29
+ });
30
+ }, C = p;
31
+ export {
32
+ C as default
33
+ };
@@ -0,0 +1,42 @@
1
+ import { c as s, T as c, P as u, a as i, b as m, C as P, Q as d } from "./VREWMQAW-DGhbq4hm.js";
2
+ import { g as v, c as C, a as e } from "./index-bzN7KmNV.js";
3
+ var h = (t) => {
4
+ const [r, o] = s({
5
+ prefix: "TanstackQueryDevtools"
6
+ }), a = v(), l = C(() => {
7
+ const n = r.theme_preference || c;
8
+ return n !== "system" ? n : a();
9
+ });
10
+ return e(d.Provider, {
11
+ value: t,
12
+ get children() {
13
+ return e(u, {
14
+ disabled: !0,
15
+ localStore: r,
16
+ setLocalStore: o,
17
+ get children() {
18
+ return e(i.Provider, {
19
+ value: l,
20
+ get children() {
21
+ return e(m, {
22
+ get children() {
23
+ return e(P, {
24
+ localStore: r,
25
+ setLocalStore: o,
26
+ get onClose() {
27
+ return t.onClose;
28
+ },
29
+ showPanelViewOnly: !0
30
+ });
31
+ }
32
+ });
33
+ }
34
+ });
35
+ }
36
+ });
37
+ }
38
+ });
39
+ }, p = h;
40
+ export {
41
+ p as default
42
+ };