Skip to content
Discussion options

You must be logged in to vote

but if I try the modification of the array, in a console.log, it works, but I can not return the newArray

You cannot return modified data from onSuccess callback and get it as actual data returned by useSWR hook.

For your use case you can modify the data within that custom hook and return it from there.

function useCustomSWR() {
    let { data } = useSWR('your-key', yourFetcherFn)

    let newArray
    if(data) {
        newArray = data.data.map((obj) => ({...obj, isNew: 'true'}))
    }

    return {
        data: newArray,
        //...
    }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@andresyapp
Comment options

Answer selected by andresyapp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants