File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -33,25 +33,42 @@ npm install react-native-sync-tasks
3333``` ts
3434import { createTask , SyncTasksManager } from ' react-native-sync-tasks' ;
3535
36- const task = createTask <{ response: string }>({
36+ type TData = {
37+ userId: number ;
38+ id: number ;
39+ title: string ;
40+ body: string ;
41+ };
42+
43+ const task = createTask <TData >({
3744 config: {
3845 url: ' https://jsonplaceholder.typicode.com/posts/1' ,
39- interval: 2000 ,
46+ // 2000ms / default 1000ms
47+ interval: 2000 ,
48+ // headers optional
4049 headers: {
4150 ' Content-Type' : ' application/json' ,
4251 ' Accept' : ' application/json' ,
4352 },
4453 },
54+ // { body: TData, status_code: number }
4555 onData : (data ) => {
4656 console .log (' DATA' , data );
4757 },
58+ // { error: string, status_code: number }
4859 onError : (error ) => {
4960 console .log (' ERROR' , error );
5061 },
5162});
5263
5364SyncTasksManager .addTask (task );
5465SyncTasksManager .startAll ();
66+ ...
67+ // stop all tasks
68+ SyncTasksManager .stopAll ();
69+ // or stop only 1 task
70+ task .stop ()
71+
5572```
5673
5774---
You can’t perform that action at this time.
0 commit comments