How can I pass props to my custom plugin #360
-
Hello, thanks for the wonderful library! So I create the following component: const LightboxSidebar = ({
children,
onButtonClick,
...props
}: {
children?: ReactNode;
onButtonClick?: () => void;
}) => {
return (
<>
{children}
<div className="lightboxSidebar">
<Button appearance="primary" onClick={onButtonClick}>
Button
</Button>
</div>
</>
);
};
export default LightboxSidebar; then I wrap it with const LightboxSidebarModule = createModule(
'LightboxSidebarModule',
LightboxSidebar
); then I create a plugin via function SidebarPlugin({
addModule,
}: {
addModule: (module: Module) => void;
}) {
addModule(LightboxSidebarModule);
} and then add it to the <Lightbox
...
plugins={[Thumbnails, Captions, Video, SidebarPlugin]}
...
/> My sidebar is being displayed but unfortunately this way I can't pass any props to my sidebar. And I need to pass some data to my |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi there! Here is how you can add TypeScript type definitions for custom lightbox props - https://yet-another-react-lightbox.com/advanced#CustomLightboxProps After that you can pass your custom props to the import Lightbox, { ComponentProps, createModule, PluginProps } from "yet-another-react-lightbox";
declare module "yet-another-react-lightbox" {
interface LightboxProps {
sidebar?: {
onButtonClick?: () => void;
};
}
}
function LightboxSidebar({ children, sidebar: { onButtonClick } = {} }: ComponentProps) {
return (
<>
{children}
{/* ... */}
</>
);
}
function SidebarPlugin({ addModule }: PluginProps) {
addModule(createModule("LightboxSidebarModule", LightboxSidebar));
}
// ...
<Lightbox
sidebar={{
onButtonClick: () => {
// ...
},
}}
plugins={[SidebarPlugin]}
// ...
/> I hope this helps! |
Beta Was this translation helpful? Give feedback.
Hi there!
Here is how you can add TypeScript type definitions for custom lightbox props - https://yet-another-react-lightbox.com/advanced#CustomLightboxProps
After that you can pass your custom props to the
Lightbox
component and access them in your plugin module.