vercel / swr

React Hooks for Data Fetching
https://swr.vercel.app
MIT License
30.56k stars 1.22k forks source link

useSWRMutation is not working with React Native New Architecture. #2986

Open ShineKidd opened 4 months ago

ShineKidd commented 4 months ago

Bug report

Repro Steps / Code Example

  1. npx create-expo-app@latest

configure app.json

 "plugins": [
      "expo-router",
      [
        "expo-build-properties",
        {
          "ios": {
            "newArchEnabled": true
          },
          "android": {
            "newArchEnabled": true
          }
        }
      ]
    ],
  1. home.tsx code example
import useSWRMutation from 'swr/mutation'

function Home () {
  const {trigger, data, error} = useSWRMutation('https://github.com', (key) => fetch(key).then(res => res.text()))

  console.log({data, error}) // always print {"data": undefined, "error": undefined}

  function submit () {
    // print error: "(NOBRIDGE) ERROR  [TypeError: Cannot read property 'add' of undefined]"
    trigger().then(console.log).catch(console.error)
  }

  return  (
     <View>
       <Button title='mutation' onPress={submit}></Button>
     </View>
     )
}
idrakimuhamad commented 1 week ago

I've facing the same issue whenever using the mutation. Probably related to the usage of transition.

image