react-native-mmkv icon indicating copy to clipboard operation
react-native-mmkv copied to clipboard

useMMKVObject hook causing issue in app.

Open wilcoxky opened this issue 2 years ago • 0 comments

I am getting this error when using useMMKVObject hook within our own custom hook wrapper. While this issue is related to redux it is being initiated by the set call in the hook. In order to work around this I switched the code to use without the hook but also believe I lose the listener effect that a hook. Any help or insight would be appreciated, and thank you for the library.

const useSubscription = (shouldHandleRedirect = false) => {
  const subscription = useSelector((state) => state.iapSubscription)
  const [localSubscription] = useMMKVObject('subscription')
  // .. replacing with line below fixes the issue
  // const localSubscription = JSON.parse(storage.getString('subscription'))

  const [isConnected, setIsConnected] = useState(true)

  const userProgram = useSelector(
    ({ firestore }) => firestore.data?.userProgram
  )
  const [hasSubscription, setHasSubscription] = useState(true)
  const userRole = useSelector(
    ({ firebase: { profile } }) => profile?.role
  )
  const dispatch = useDispatch()

  const navigation = useNavigation()

  useEffect(() => {
     // Work with data...
  }, [subscription, localSubscription, isConnected, userRole, userProgram])

 ... 
}
image

wilcoxky avatar Aug 02 '22 23:08 wilcoxky