It seems that the error is returned because the LightBox component is not properly configured. Could you share it with us in order to take a look?
Just to clarify, you may need something like this:
A LightboxImage component
Inside this component you’ll use the Lightbox from the library you share, and it gets the props from the <img>
tag attributes. You have to make sure you pass the correct parameters to the <Lightbox>
component. It could be similar to this:
import Lightbox from 'react-lightbox-component';
import { connect } from "frontity";
const LightboxImage = (props) => (
<div>
<Lightbox images={
[
{
src: props.src,
title: props.alt,
description: props.description
}
]
}/>
</div>
);
export default connect(LightboxImage);
Not sure if inside the Lightbox library, title and description are mandatory fields. But if not, you could make that optional.
A new processor for the images
You have create a new processor for the images in order to use your new component instead of the default one. It could be something like the current one, adapting it to your own needs, but using your component.
import LightboxImage from "../your-new-component";
const lightboxImage = {
// We can add a name to identify it later.
name: "image",
// We can add a priority so it executes before or after other processors.
priority: 5,
// Only process the node it if it's an image.
test: node => node.component === "img",
process: node => {
// If the image is inside a <noscript> tag, we don't want to process it.
if (node.parent.component === "noscript") return null;
// Many WP lazy load plugins move the real "src" to "data-src", so we move it back.
if (node.props["data-src"])
node.props.src = node.props["data-src"];
if (node.props["data-srcset"])
node.props.srcSet = node.props["data-srcset"];
// We tell Html2React that it should use the <LightboxImage /> component
node.component = LightboxImage;
return node;
}
};
export default lightboxImage;
Add the new processor to your theme
You need to include the new processor in your settings so it’s executed by @frontity/html2react
package. You’ll need to include it in the index.js
file of your theme.
import lightboxImage from "../your-processor-file";
const marsTheme = {
...
libraries: {
html2react: {
processors: [lightboxImage]
}
}
...
};
export default marsTheme;
Hope this helps, let us know if you solve the problem!