image-focus icon indicating copy to clipboard operation
image-focus copied to clipboard

How to use this with react

Open vabatta opened this issue 5 years ago • 6 comments

Hi,

how can I use this with react?

vabatta avatar Feb 04 '20 18:02 vabatta

Hi

I have used this in a React project previously. I don't have access to the code any more as it remains with my former company but I might be able to help. What are you trying to do? In my experience the best way is to create a React wrapper around the necessary component that stores the state (in this case probably the focused coordinates) and passes any necessary handlers that update this state to the image-focus components.

andomain avatar Feb 05 '20 09:02 andomain

Okay, the issue that I am facing is that I cannot 'unmount' the focused image. Once I wrapped my ref with the FocusedImage, I want to be able to return back to the state where my img element is just an img element (no inline styles, no event attached, ...). (img.stopListening is not enough)

vabatta avatar Feb 05 '20 13:02 vabatta

Gotcha! Sounds like we need to add a .dispose() method?

third774 avatar Feb 05 '20 16:02 third774

Sounds good. I really want to be able to attach and detach the library to an element dynamically.

vabatta avatar Feb 07 '20 21:02 vabatta

@third774 any update on this? I'd love this feature as well

mcabs3 avatar Mar 02 '21 19:03 mcabs3

I have addressed this with an initial draft (that I have working) in this PR.

mcabs3 avatar Mar 09 '21 18:03 mcabs3

FWIW at this point I'd just recommend using object-position.

https://kevinkipp.com/blog/til-object-position/

third774 avatar Jan 12 '24 04:01 third774