I got a very strange issue. I am using a ref (pointing to an image element) that is provided via react context. Unfortunately the project is quite complicated, but I will try to explain the component structure.
<ReactContext>
<ComponentA>
<ComponentB />
<ComponentC>
<imageWithRef />
</ComponentC>
</ComponentA>
</ReactContext>
Component a makes a network request to request the url used as the image source.
The react context provides the image ref
. That ref
is used in several other components for calculations.
Whilst component c seems to be quite happy with that ref, component b shows a very strange behavior.
The function, that uses the provided ref, logs it to my browser console.
console.log({ imageRef, imageRefCurrent: imageRef.current });
// log:
{imageRef: {current: img#analysis_image.sc-hazodl.gljftv}, imageRefCurrent: undefined}
It seems to be Schrödinger's cat and I cannot find the reason for my issue.. Does anybody have an idea how to fix it?
If needed, I can provide further information.
Best wishes