prism-react-renderer icon indicating copy to clipboard operation
prism-react-renderer copied to clipboard

Render children using jsx syntax

Open bendtherules opened this issue 3 years ago • 0 comments

https://github.com/FormidableLabs/prism-react-renderer/blob/86c05728b6cbea735480a8354546da77ae8b00d9/src/components/Highlight.js#L134

In Highlight.js (and probably other parents), children is rendered by calling it as a function. This can cause a subtle but hard-to-find issue depending on user's code.

  1. If user passes a function component (using hooks) as child, that will fail
  2. There can be other subtle differences because of how react renders function component lazily now-a-days.

All of that can be solved by just rendering it as jsx, like <Children />. Then react will treat it as a proper component.

Backwards compat - Because normal functions will work just the same as pure function component, they will continue to work in the same way. It will not break existing userland code.

bendtherules avatar Sep 30 '20 15:09 bendtherules