question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should useDerivedValue cause a rerender?

See original GitHub issue

Description

If I format a date on the ui thread like so…

const date = useDerivedValue(() => {
    const d = interpolate(translation.x.value, [0, width], [MIN, MAX]);
    return formatDateOnUI(d);
});

return <Text>{date}</Text>

In this example date will update (can check by logging d before return), however it will not update the UI… I can hack around this by calling some setState with runOnJS and that triggers a re-render but of course affects fps on the JS thread

Package versions

  • React: 16.13.1
  • React Native: ~0.63.3
  • React Native Reanimated: 2.0.0-rc.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
karol-bisztygacommented, Jan 5, 2021

you only want to ensure it runs only once

I think that does not break a thing, however, it would be inefficient as it overwrites collections on both, js and the native side.

1reaction
jakub-gonetcommented, Jan 5, 2021

@anastely, you can add it wherever you want, you only want to ensure it runs only once. index.js or App.js or any standalone configuration file that is included there is fine. Using that in a component file (outside of component definition) is also fine but you may prefer a more “global” place to keep your configs in.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useDerivedValue | React Native Reanimated
This hook allows for creating shared value reference that can change in ... cause this hook to receive updated values during rerender of...
Read more >
Set state with same value using hooks will cause a rerender?
It won't re-render the component if you call setState with the same value. Try this out: import React, { useState, useEffect } from...
Read more >
why my component are always rerender although I use memo
This is the correct answer. handleAddOrRemoveFromWishList is changing every time, so memo sees it as changed props and re-renders. If you use ...
Read more >
When does React re-render components? - Felix Gerschau
Real DOM updates are slow because they cause an actual re-draw of the UI ... In React class components, you can force a...
Read more >
Shared Values | React Native Reanimated
If you are familiar with React Native's Animated API you can compare them to ... and in order to read the data we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found