Skip to content

Commit dd28544

Browse files
authored
Merge pull request #203 from atomic-state/enhancements/useServerAction
enh(useServerAction):
2 parents 86d7d93 + e809051 commit dd28544

File tree

5 files changed

+45
-44
lines changed

5 files changed

+45
-44
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-react",
3-
"version": "3.7.4",
3+
"version": "3.7.5",
44
"description": "React hooks for data fetching",
55
"main": "dist/index.js",
66
"scripts": {

src/hooks/others.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ export function useServerAction<T extends (args: any) => any>(
687687
> & {
688688
onSubmit?:
689689
| 'reset'
690-
| ((form: HTMLFormElement, data: Parameters<T>[0]) => void)
690+
| ((form: HTMLFormElement, formData: Parameters<T>[0]) => void)
691691
} & (Parameters<T>[0] extends typeof undefined
692692
? {}
693693
: {
@@ -710,6 +710,7 @@ export function useServerAction<T extends (args: any) => any>(
710710
return { data, error, status }
711711
},
712712
id: mockServerActionId,
713+
auto: false,
713714
...config,
714715
onResolve(...c) {
715716
if (config?.onResolve) config.onResolve(...c)
@@ -759,7 +760,7 @@ export function useServerMutation<T extends (args: any) => any>(
759760
> & {
760761
onSubmit?:
761762
| 'reset'
762-
| ((form: HTMLFormElement, data: Parameters<T>[0]) => void)
763+
| ((form: HTMLFormElement, formData: Parameters<T>[0]) => void)
763764
} & (Parameters<T>[0] extends typeof undefined
764765
? {}
765766
: {

src/internal/constants.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ const ATTEMPT_INTERVAL = 2
99
const REVALIDATE_ON_FOCUS = false
1010
const RETRY_ON_RECONNECT = true
1111
const REVALIDATE_ON_MOUNT = true
12-
const DEFAULT_GRAPHQL_PATH = "/graphql"
12+
const DEFAULT_GRAPHQL_PATH = '/graphql'
1313
const DEFAULT_RESOLVER = (e: any) => e.json()
1414
const DEFAULT_MIDDLEWARE = (incoming: any, previous: any) => incoming
1515
const DEFAULT_TRANSFORM = (fetchData: any) => fetchData
1616

1717
const METHODS = {
18-
GET: "GET",
19-
DELETE: "DELETE",
20-
HEAD: "HEAD",
21-
OPTIONS: "OPTIONS",
22-
POST: "POST",
23-
PUT: "PUT",
24-
PATCH: "PATCH",
25-
PURGE: "PURGE",
26-
LINK: "LINK",
27-
UNLINK: "UNLINK",
18+
GET: 'GET',
19+
DELETE: 'DELETE',
20+
HEAD: 'HEAD',
21+
OPTIONS: 'OPTIONS',
22+
POST: 'POST',
23+
PUT: 'PUT',
24+
PATCH: 'PATCH',
25+
PURGE: 'PURGE',
26+
LINK: 'LINK',
27+
UNLINK: 'UNLINK'
2828
}
2929

3030
const UNITS_MILISECONDS_EQUIVALENTS = {
@@ -35,7 +35,7 @@ const UNITS_MILISECONDS_EQUIVALENTS = {
3535
d: 86400000,
3636
we: 604800000,
3737
mo: 2629800000,
38-
y: 31536000000,
38+
y: 31536000000
3939
}
4040

4141
export {
@@ -55,5 +55,5 @@ export {
5555
METHODS,
5656
UNITS_MILISECONDS_EQUIVALENTS,
5757
DEFAULT_MIDDLEWARE,
58-
DEFAULT_TRANSFORM,
58+
DEFAULT_TRANSFORM
5959
}

src/internal/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
"use client"
2-
import { createContext, useContext } from "react"
1+
'use client'
2+
import { createContext, useContext } from 'react'
33

4-
import { CacheStoreType, FetchContextType } from "../types"
4+
import { CacheStoreType, FetchContextType } from '../types'
55
import {
66
ATTEMPTS,
77
ATTEMPT_INTERVAL,
@@ -15,9 +15,9 @@ import {
1515
QUERY,
1616
RETRY_ON_RECONNECT,
1717
REVALIDATE_ON_FOCUS,
18-
REVALIDATE_ON_MOUNT,
19-
} from "./constants"
20-
import { $context } from "./shared"
18+
REVALIDATE_ON_MOUNT
19+
} from './constants'
20+
import { $context } from './shared'
2121

2222
/**
2323
* This marks which requests are running
@@ -135,7 +135,7 @@ export const defaultCache: CacheStoreType = {
135135
},
136136
remove(k) {
137137
resolvedRequests.delete(k)
138-
},
138+
}
139139
}
140140

141141
const requestsSubscribers = new Map()
@@ -163,7 +163,7 @@ export const requestsProvider = {
163163
listener(payload)
164164
})
165165
}
166-
},
166+
}
167167
}
168168

169169
const defaultContextVaue: FetchContextType = {
@@ -181,7 +181,7 @@ const defaultContextVaue: FetchContextType = {
181181
cacheIfError: true,
182182
middleware: DEFAULT_MIDDLEWARE,
183183
transform: DEFAULT_TRANSFORM,
184-
...$context.value,
184+
...$context.value
185185
}
186186

187187
export const FetchContext = createContext<FetchContextType>(defaultContextVaue)

src/types/index.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
export type HTTP_METHODS =
2-
| "GET"
3-
| "DELETE"
4-
| "HEAD"
5-
| "OPTIONS"
6-
| "POST"
7-
| "PUT"
8-
| "PATCH"
9-
| "PURGE"
10-
| "LINK"
11-
| "UNLINK"
2+
| 'GET'
3+
| 'DELETE'
4+
| 'HEAD'
5+
| 'OPTIONS'
6+
| 'POST'
7+
| 'PUT'
8+
| 'PATCH'
9+
| 'PURGE'
10+
| 'LINK'
11+
| 'UNLINK'
1212

1313
export type FetchContextType = {
1414
clientOnly?: boolean
@@ -83,15 +83,15 @@ export type FetchContextType = {
8383
ctx: FetchContextType
8484
): void
8585
maxCacheAge?: TimeSpan
86-
} & Omit<RequestInit, "body">
86+
} & Omit<RequestInit, 'body'>
8787

8888
export type CacheStoreType = {
8989
get(k?: any): any
9090
set(k?: any, v?: any): any
9191
remove?(k?: any): any
9292
}
9393

94-
export type CustomResponse<T> = Omit<Response, "json"> & {
94+
export type CustomResponse<T> = Omit<Response, 'json'> & {
9595
json(): Promise<T>
9696
}
9797

@@ -103,7 +103,7 @@ export type RequestWithBody = <R = any, BodyType = any>(
103103
/**
104104
* The request configuration
105105
*/
106-
reqConfig?: Omit<RequestInit & FetchConfigType<R, BodyType>, "suspense"> & {
106+
reqConfig?: Omit<RequestInit & FetchConfigType<R, BodyType>, 'suspense'> & {
107107
/**
108108
* Default value
109109
*/
@@ -144,7 +144,7 @@ export type RequestWithBody = <R = any, BodyType = any>(
144144

145145
export type TimeSpan =
146146
| number
147-
| `${string} ${"ms" | "sec" | "min" | "h" | "d" | "we" | "mo" | "y"}`
147+
| `${string} ${'ms' | 'sec' | 'min' | 'h' | 'd' | 'we' | 'mo' | 'y'}`
148148

149149
/**
150150
* An imperative version of the `useFetch` hook
@@ -165,7 +165,7 @@ export type ImperativeFetch = {
165165

166166
export type FetchConfigType<FetchDataType = any, BodyType = any> = Omit<
167167
RequestInit,
168-
"body" | "headers"
168+
'body' | 'headers'
169169
> & {
170170
headers?: any
171171
/**
@@ -219,7 +219,7 @@ export type FetchConfigType<FetchDataType = any, BodyType = any> = Omit<
219219
* @default true
220220
*/
221221
memory?: boolean
222-
onSubmit?: "reset" | ((form: HTMLFormElement, data: FormData) => void)
222+
onSubmit?: 'reset' | ((form: HTMLFormElement, data: FormData) => void)
223223
/**
224224
* Function to run when request is resolved succesfuly
225225
*/
@@ -337,11 +337,11 @@ export type FetchConfigType<FetchDataType = any, BodyType = any> = Omit<
337337
/**
338338
* Will run when the request is sent
339339
*/
340-
onFetchStart?: FetchContextType["onFetchStart"]
340+
onFetchStart?: FetchContextType['onFetchStart']
341341
/**
342342
* Will run when the response is received
343343
*/
344-
onFetchEnd?: FetchContextType["onFetchEnd"]
344+
onFetchEnd?: FetchContextType['onFetchEnd']
345345
/**
346346
* If `true`, the last resolved value be returned as `data` if the request fails. If `false`, the default value will be returned instead
347347
*
@@ -357,7 +357,7 @@ export type FetchConfigType<FetchDataType = any, BodyType = any> = Omit<
357357
// If first argument is a string
358358
export type FetchConfigTypeNoUrl<FetchDataType = any, BodyType = any> = Omit<
359359
FetchConfigType<FetchDataType, BodyType>,
360-
"url"
360+
'url'
361361
>
362362

363363
/**

0 commit comments

Comments
 (0)