Skip to content

Commit

Permalink
Fix: pass object-type mark props through to serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyward committed Feb 26, 2021
1 parent f1ea54c commit f1c2466
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,22 @@ const buildSerializer = (serializers) => {
const scrubMarkProps = (serializers) =>
Object.entries(serializers).reduce((output, [name, serializer]) => {
if (serializer) {
const wrapper = ({ _type, _key, mark, markKey, children, ...props }) =>
React.createElement(serializer, props, children)
const wrapper = ({ _type, _key, mark, markKey, children, ...props }) => {
// Sometimes the `mark` prop is a string that we want to ignore,
// but other times it is an object with _key, _type, and other
// props that we want to pass through. In that case, we iterate
// through the `mark` object properties and add them to the
// `props` that we pass to the serializer.
if (typeof mark === "object") {
const { _type, _key, ...markProps } = mark
Object.entries(markProps).forEach(([name, value]) => {
props[name] = value
})
}

return React.createElement(serializer, props, children)
}

wrapper.displayName = `${upperFirst(name)}Wrapper`
output[name] = wrapper
}
Expand Down

0 comments on commit f1c2466

Please sign in to comment.