Skip to content

Commit 82f0e20

Browse files
committed
fix: make data & error optional field; use context const in useSWR
1 parent 9cf0cd2 commit 82f0e20

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/lib/swr.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ interface Params<T> {
1919
}
2020

2121
interface Context<T> {
22-
data: T | undefined;
23-
error: Error | undefined;
22+
data?: T;
23+
error?: Error;
2424
isLoading: boolean;
2525
isFetching: boolean;
2626
}
@@ -30,8 +30,6 @@ interface SWRStore<T> extends Readable<Context<T>> {
3030
}
3131

3232
const defaultContext = {
33-
data: undefined,
34-
error: undefined,
3533
isLoading: false,
3634
isFetching: false,
3735
};
@@ -45,11 +43,13 @@ const defaultOptions = {
4543
export function useSWR<T>(): SWRStore<T> {
4644
const client = getClient();
4745

48-
const store = writable<Context<T>>({ ...defaultContext });
46+
const context = { ...defaultContext };
47+
48+
const store = writable<Context<T>>(context);
4949

5050
const fsm = newFSM({
5151
config: swrMachine,
52-
context: { ...defaultContext },
52+
context,
5353
receiveFn: (state, ctx) => {
5454
store.set({ state, ...ctx });
5555

0 commit comments

Comments
 (0)