Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useSWRInfinite with types #2851

Open
wcastand opened this issue Dec 8, 2023 · 0 comments
Open

useSWRInfinite with types #2851

wcastand opened this issue Dec 8, 2023 · 0 comments

Comments

@wcastand
Copy link

wcastand commented Dec 8, 2023

Bug report

Description / Observed Behavior

using useSWRInfinite doesn't provide the proper types because it assumes the type is an array but i'm using a cursor based so the response is different.

type CorrectResponseType = {
	transactions: Transaction[]
	nextCursor?: string
	nextStartDate?: string
}

const value = useSWRInfinite<Transaction>(getKey(params))

but value.data is Transaction[] and if i pass CorrectResponseType then value.data becomes CorrectResponseType[] which is incorrect.

Expected Behavior

to not modify the response and let me decide what it returns.

CorrectResponseTypec should not be transformed as CorrectResponseType[] in the return value.

Repro Steps / Code Example

Or share your code snippet or a CodeSandbox link is also appreciated!

I tried to make a codesandbox but it couldn't find the swr package so the type were not working so i gave up (no time sorry, have to work on things lol)

Additional Context

using "swr": "^2.2.4"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant