Elius94 / react-photo-sphere-viewer

Photosphere Viewer for React.JS
MIT License
69 stars 21 forks source link

Received an error message when using createRef() #23

Closed nguyen1998pr closed 11 months ago

nguyen1998pr commented 1 year ago

Hi i was following the Readme and got the error when trying to use createRef. The error description is shown in the image below:

image

How to fix that?

Elius94 commented 1 year ago

Hi. The instance type is defined like this:

const ReactPhotoSphereViewer: React.ForwardRefExoticComponent<Props & React.RefAttributes<unknown>>

Where Props is a ViewerConfig extender type that is exported from the library.

export interface Props extends ViewerConfig {
    src: string;
    navbar?: boolean | string | Array<string | NavbarCustomButton>;
    height: string;
    width?: string;
    containerClass?: string;
    littlePlanet?: boolean;
    fishEye?: boolean | number;
    lang?: {
        zoom: string;
        zoomOut: string;
        zoomIn: string;
        moveUp: string;
        moveDown: string;
        moveLeft: string;
        moveRight: string;
        download: string;
        fullscreen: string;
        menu: string;
        close: string;
        twoFingers: string;
        ctrlZoom: string;
        loadError: string;
        [K: string]: string;
    };
    // Events
    onPositionChange?(lat: number, lng: number, instance: Viewer): void;
    onZoomChange?(data: events.ZoomUpdatedEvent & { type: "zoom-updated"; }, instance: Viewer): void;
    onClick?(data: events.ClickEvent & { type: "click"; }, instance: Viewer): void;
    onDblclick?(data: events.ClickEvent & { type: "dblclick"; }, instance: Viewer): void;
    onReady?(instance: Viewer): void;
}

Let me know if it works

nguyen1998pr commented 1 year ago

I tried this but can't find the "zoom" method

image

In Readme: https://github.com/Elius94/react-photo-sphere-viewer#methods

Elius94 commented 1 year ago

I think it's a bug in the typescript. I probably need to declare the methods explicitly, because passing from a forwardRef doesn't seem to pass them automatically. In addition these methods are useImperativeHandle. If you want you can try to fix it by contributing to the project and once it works you can PR me. Otherwise as soon as I can I will look at it, but not before Monday.

nguyen1998pr commented 1 year ago

hi Elius94, do you have any update for this issue?

Elius94 commented 1 year ago

Hi @nguyen1998pr unfortunately I have been very busy these days, I still have to look at it! if you want you can give me a hand and contribute! anyway as soon as I have time I will look at it!

Elius94 commented 12 months ago

Hello! With the new release of yesterday it should'nt happen anymore. can you test it?