Replies: 3 comments 2 replies
-
I had a look into the code, it looks like easy to extend the api to accept a SharedValue as useSharedValue parameter. |
Beta Was this translation helpful? Give feedback.
-
Hey @freeboub! Sorry for the late response. You can safely read the function useOtherSharedValue<T>(value: SharedValue<T>): SharedValue<T> {
const initialValueRef = useRef<T | undefined>(undefined);
const isFirstRenderRef = useRef(true);
if (isFirstRenderRef.current) {
initialValueRef.current = value.value;
isFirstRenderRef.current = false;
}
return useSharedValue(initialValueRef.current as T);
} Since we need the initial value only once, when the |
Beta Was this translation helpful? Give feedback.
-
Thank you for the feedback, we can close this topic, thank you very much ! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
For some reason, I need to initialize a SharedValue with the value of another SharedValue (ParentComponent provide a SharedValue to ChildComponent and the ChildComponent need to animate the value in another way).
Can you please explicite what is the best way to do that ?
this natural way is intialize it like this:
But it causes a warning on last version as we access to the .value from JS thread.
I currently workaround it like this:
But it is not really clean as we have a small time where childSharedValue is 0
ideally, I would like to write it like this:
but use useSharedValue doesn't accept a SharedValue as prop, but I think it can be an interesting enhancement.
Beta Was this translation helpful? Give feedback.
All reactions