-
In my project our API endpoints are accessed as (constant) functions likes import {getBook} from '../api/book'
function Foo() {
const id = ...;
const {data} = useSWR([getBook, id], () => {
return getBook(id)
})
...
} Is it okay to use function as key like this, as long as it is inside an array? |
Beta Was this translation helpful? Give feedback.
Answered by
shuding
May 3, 2022
Replies: 2 comments
-
I'm not sure whether SWR officially supports this, but your example works fine if |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yep just like @koba04 said, it's a valid use case as long as you don't directly pass a function. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
chiawendt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yep just like @koba04 said, it's a valid use case as long as you don't directly pass a function.