@codella-software/react 2.0.1 → 2.2.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 CHANGED
@@ -7,8 +7,8 @@ React hooks for Codella core services - FormBuilder, TableBuilder, FiltersAndSor
7
7
  - **useFormBuilder** - Manage form state, validation, and submission
8
8
  - **useTableService** - Manage dynamic table data, filtering, and sorting
9
9
  - **useFiltersAndSort** - Handle complex filtering and sorting logic
10
- - **useTabsService** - Manage tab state and navigation
11
- - **useAPIService** - RESTful API client with authentication
10
+ - **useTabsService** - Manage tab state and navigation (use CLI templates for responsive components)
11
+ - **useAPIService** - RESTful API client with authentication, interceptors, and middleware hooks
12
12
  - **useLiveUpdates** - Real-time data updates via WebSocket or Server-Sent Events
13
13
 
14
14
  ## Installation
@@ -69,20 +69,52 @@ function MyTable() {
69
69
 
70
70
  ```typescript
71
71
  import { useAPIService } from '@codella-software/react';
72
+ import { useEffect, useState } from 'react';
72
73
 
73
74
  function UsersList() {
75
+ const [users, setUsers] = useState([]);
76
+ const [loading, setLoading] = useState(false);
77
+
74
78
  const api = useAPIService({
75
- baseURL: 'https://api.example.com'
79
+ baseURL: 'https://api.example.com',
80
+ hooks: {
81
+ onBeforeRequest: () => setLoading(true),
82
+ onAfterResponse: () => setLoading(false),
83
+ onError: (ctx) => console.error('Error:', ctx.error)
84
+ }
76
85
  });
77
86
 
87
+ // Add request interceptor to include custom headers
88
+ useEffect(() => {
89
+ api.interceptors.request.use((config) => ({
90
+ ...config,
91
+ headers: { ...config.headers, 'X-App-Version': '2.0' }
92
+ }));
93
+
94
+ // Add response interceptor to transform data
95
+ api.interceptors.response.use((response) => ({
96
+ ...response,
97
+ data: Array.isArray(response.data) ? response.data : [response.data]
98
+ }));
99
+ }, [api]);
100
+
78
101
  useEffect(() => {
79
102
  api.get('/users').then(setUsers);
80
103
  }, [api]);
81
104
 
82
- return <div>{/* Display users */}</div>;
105
+ return (
106
+ <div>
107
+ {loading && <p>Loading...</p>}
108
+ <ul>
109
+ {users.map(user => <li key={user.id}>{user.name}</li>)}
110
+ </ul>
111
+ </div>
112
+ );
83
113
  }
84
114
  ```
85
115
 
116
+ See [API Service Documentation](https://CodellaSoftware.github.io/codella-utils/api-service/) for interceptors, middleware hooks, and authentication patterns.
117
+
86
118
  ## Documentation
87
119
 
88
120
  For full API documentation, visit [https://CodellaSoftware.github.io/codella-utils/](https://CodellaSoftware.github.io/codella-utils/)