prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
152 stars 40 forks source link

Custom props on the final component #35

Closed Simounet closed 4 years ago

Simounet commented 5 years ago

Hi there, Maybe I didn't saw the option to give props (like className) to the the final component. My use case is styling components with styled-jsx, I need to set the className prop on the final component that will be styled. Have a nice day.

hypervillain commented 4 years ago

Hey @Simounet,

you should now be able to pass a className prop (and more) on the final component. See https://github.com/prismicio/prismic-reactjs/pull/41

Note that if you need to do this on children components, you will need to rely on htmlSerializer prop. See this: https://prismic.io/docs/javascript/beyond-the-api/html-serializer

Let me know if I can help further, Hugo

mlynch commented 3 years ago

Wanted to add another thought here. Currently it's not possible to add custom props to RichText and then access those in the htmlSerializer. Instead, the props get put on the Component which is a Fragment by default.

Is there a way to actually get those props to pass them down to children in htmlSerializer?