prismicio / prismic-react

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

Expose serialisation functions #50

Closed haf closed 3 years ago

haf commented 4 years ago

If I'm supposed to be able to override singular element type serialisation functions, it would be great to be able to delegate all other types of elements into this code-base. Hence; if you could expose your serialisers, it would be appreciated.

hypervillain commented 3 years ago

Hey @haf, can you give me more details of what you mean? Would you like to be able to specify your own serialize functions, like our serializeStandardTag for example?

haf commented 3 years ago

No, I don't, I mean exposing your existing per-type serialisation functions.

hypervillain commented 3 years ago

Ok, we can definitely do that. How would you make use of them?

haf commented 3 years ago

I ended up copying your code instead; but what I would have done would have been to delegate to them from my own clone of your main serialise function, as to keep the behaviour the same for everything except the single serialisation function I wished to override.

The use case was rendering NextJS links.

hypervillain commented 3 years ago

Ok, it definitely makes sense!

Have you tried using the elements property?

<RichText render={myField} elements={{ hyperlink: () => <NextLink /> }}
haf commented 3 years ago

I think I tried it, but it’s been too long and I don’t remember why I didn’t use it. Sorry

hypervillain commented 3 years ago

haha no problem, we added the prop not so long ago, it may even not have been available at the time! Thanks for your contribution ✌️