remarkablemark/html-react-parser

Question: Replace node type text by a React Component

josue-suarez-wt opened this issue · 2 comments

Question

Is it possible to replace a domNode type text by a React Component? For example

if (domNode.type === 'text') { return <Text field={{ ...fieldsContent, value: domNode.data }} style={{ color: 'red' }} />;

Keywords

html-react-parser
react component
text

@josue-suarez-wt yes, this is possible and a valid use-case of this library. See README

Thanks for confirming! Seems that my issue was because of returning an array done via .map.

In that case, returning a fragment wrapping the array works fine!

const jsxFragments = [...].map(...);
return <>{jsxFragments}</>;