Coder Social home page Coder Social logo

Comments (5)

gsathya avatar gsathya commented on September 1, 2024 3

The compiler should actually compile this fine, I think the healthcheck script doesn't track the reanimated import and turn on the correct type information. This should just be a fix in the health check script.

from react.

josephsavona avatar josephsavona commented on September 1, 2024 2

An alternative would be to use your own helper for assigning the value. Instead of x.value = y, create your own updateSharedValue(sharedValue, value) helper function and call it.

from react.

josephsavona avatar josephsavona commented on September 1, 2024

Thanks for posting. We've discussed this previously with the Reanimated team.

React requires that values returned from hooks are immutable. This is because React's reactivity model is fundamentally based on immutability, both for developer reasoning and to enable features such as concurrent rendering, where React may render multiple distinct versions of your UI with different base states.

The one exception to this rule is the ref type (created with createRef() or useRef()). They are the escape hatch for when you need a value that can be directly mutated, rather than copying (spreading) and changing the new version as we do with state values. The reason that refs can be "safely" mutated is that they can't be accessed during render, which helps developers avoid accidentally rendering stale results.

Our recommendation for APIs such as Reanimated's SharedValue API:

  • Disallow access to the .value during rendering, to help developers avoid accidentally reading the value outside of Reanimated APIs which will subscribe for updates
  • Use a function for updates instead of property assignment, Eg setValue(sharedValue, value) instead of sharedValue.value = value.

from react.

gkueny avatar gkueny commented on September 1, 2024

Thankโ€™s @josephsavona for the explanation.

If I understand correctly, as react-native developer we have to wait some api design update by react-native-reanimated team to be able to use react-compiler with our component that use x.value = y; syntax ?

from react.

AlirezaHadjar avatar AlirezaHadjar commented on September 1, 2024

Thank you for the insight ๐Ÿ™Œ

from react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.