Skip to content

Commit

Permalink
refactor: define properties with enumerable: true
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed Jan 12, 2021
1 parent ac512da commit 352e03f
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/use-swr-infinite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,23 +217,26 @@ function useSWRInfinite<Data = any, Error = any>(
)

// Use getter functions to avoid unnecessary re-renders caused by triggering all the getters of the returned swr object
return {
get error() {
return swr.error
const swrInfinite = { size, setSize, mutate }
Object.defineProperties(swrInfinite, {
error: {
get: () => swr.error,
enumerable: true
},
get data() {
return swr.data
data: {
get: () => swr.data,
enumerable: true
},
get revalidate() {
return swr.revalidate
revalidate: {
get: () => swr.revalidate,
enumerable: true
},
get isValidating() {
return swr.isValidating
},
mutate,
size,
setSize
} as SWRInfiniteResponseInterface<Data, Error>
isValidating: {
get: () => swr.isValidating,
enumerable: true
}
})
return swrInfinite as SWRInfiniteResponseInterface<Data, Error>
}

export {
Expand Down

0 comments on commit 352e03f

Please sign in to comment.