gilbarbara / react-joyride

Create guided tours in your apps
https://react-joyride.com/
MIT License
6.62k stars 519 forks source link

How to pass helpers in tooltipComponent ? #956

Closed mtr1990 closed 8 months ago

mtr1990 commented 8 months ago

🐛 Bug Report

Can't pass helpers in tooltipComponent to be able to access the go, reset methods...

Expected behavior

Pass helpers in tooltipComponent to be able to access the go, reset methods..

Link to repl or repo (highly encouraged)

Based on the example code you provided. (CustomComponents) https://codesandbox.io/p/sandbox/condescending-payne-4vnnxm?file=%2Fsrc%2FCustomComponents%2Findex.tsx%3A280%2C11

gilbarbara commented 8 months ago

Hey @mtr1990

Yes, out of the box, the tooltipComponent doesn't get the helpers. You could enhance your custom component before passing it to Joyride.

function Tooltip(props: TooltipRenderProps & { helpers?: StoreHelpers }) {
    ...
}

function App() {
    const TooltipWithHelpers = useCallback(
        /** You could set this directly in the props, but it would be recreated at every render.
         * So, using the useCallback is better for this case.
        */
        (tooltipProps: TooltipRenderProps) => <Tooltip helpers={helpers.current} {...tooltipProps} />,
        [],
    );

    return (
        <>
            <Joyride  tooltipComponent={TooltipWithHelpers} />
            ...
        </>
    );
}