I use PrismicDOM.RichText.asHtml with image type or Slice type but receive error: e.reduce is not a function or t.map is not a function. Could you help me fix it?
`PrismicDOM.RichText.asHtml(section, linkResolver, htmlSerializer)
index.js:1472 TypeError: Cannot read property 'map' of undefined
at prismic-dom.min.js:532
at prismic-dom.min.js:541
at Array.reduce (<anonymous>)
at Function.value (prismic-dom.min.js:528)
at Object.t.default [as serialize] (prismic-dom.min.js:1018)
at Object.asHtml (prismic-dom.min.js:238)
at prismic.js:86
at Array.map (<anonymous>)
at asHTML (prismic.js:79)
at prismic.js:117
at Array.forEach (<anonymous>)
at prismic.js:115`
In order to be able to help with this, I need you to provide me with a code snippet of the code that is throwing the error with the full error stack to know in what line the library is breaking.
const linkResolver = (doc) => {
// Pretty URLs for known types
if (doc.type === 'blog') return "/post/" + doc.uid;
if (doc.type === 'page') return "/" + doc.uid;
// Fallback for other types, in case new custom types get created
return "/doc/" + doc.id;
};
Well, it depends on what technology you are using, if you are using pure javaScript then your query would look like this:
var PrismicDOM = require('prismic-dom');
document.data.body.map(function(slice) {
// Render the right markup for a given slice type
switch(slice.slice_type) {
case 'text': return PrismicDOM.RichText.asHtml(slice.primary.rich_text)
case 'image-gallery':
return slice.items.map(function(image) {
return image.gallery_image.url
})
}
})
Where the body property the document.data object is your sliceZone that includes a list of slices, to learn more about templating slices in JS please refer to the document.