software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
9.01k stars 1.3k forks source link

useSharedValue is not a function #1426

Closed shockdesign closed 3 years ago

shockdesign commented 3 years ago

Description

Followed the steps to install alpha 8, then proceeded to setup my view, however none of the react-native-reanimated 2 hooks are available?

Looking at the default Animated object and I can't see the hooks there either.

image

And looking node_modules/react-native-reanimated/src/reanimated2 has Hooks.js which has the correct hooks.

babel.config.js looks like:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: ['react-native-reanimated/plugin'],
  env: {
    production: {
      plugins: ['react-native-paper/babel'],
    },
  },
}

Screenshots

Simulator Screen Shot - iPhone 11 - 2020-11-11 at 22 56 36

Steps To Reproduce

  1. Try using any of the new hooks via import

Expected behavior

Hook is available

Actual behavior

Hook isn't found

Snack or minimal code example

import React from 'react'
import Animated, { useSharedValue } from 'react-native-reanimated'

export const Screen = ({ route, navigation }) => {
  const height = useSharedValue(0)

  return null
}

Package versions

mdcone commented 3 years ago

Same thing happened to me because the bundler cached the old module. Run the bundler manually with the --clear-cache flag and see if that fixes things.

shockdesign commented 3 years ago

npm cache clean --force and manually deleting node_modules/ and reinstalling still has the same issue..

@mdcone which bundler are you using --clear-cache with?

mdcone commented 3 years ago

@shockdesign, the react-native bundler. To get rid of its cache fire it up with react-native start --clear-cache.

jakub-gonet commented 3 years ago

As @mdcone said this is likely related to stale metro cache. You can try clearing watchman cache, here's a gist that should clear all JS artifacts. If you're using iOS remember to remove Pods too.

I'm closing this but if you'll have further problems with that don't hesitate to reply.

canberkardic commented 3 years ago

I have the same problem too. Can't find any solution. Deleting cache, watchman, node_modules, Pods is not the solution.

jakub-gonet commented 3 years ago

@canberkardic do you use npm by any chance? We saw similar reports in the past. Try using yarn and if you can, please provide a reproducible repository – that will greatly help us resolve this error.