Skip to content

Instantly share code, notes, and snippets.

@devknoll
Last active September 10, 2019 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devknoll/c573bce2bfcc61f5703e47fae2e0675f to your computer and use it in GitHub Desktop.
Save devknoll/c573bce2bfcc61f5703e47fae2e0675f to your computer and use it in GitHub Desktop.

Idea: React.Freezer

React.Freezer takes a frozen prop, that, when true:

  • Prevents React from making any mutations to the tree rooted at children
  • Logically unmounts any children and event handlers, as if children was set to null

Could form the basis for React escape hatches in general. E.g. dangerouslySetInnerHTML on every HTML Host element could be deprecated and instead be replaced with:

<React.Freezer children={{dangerousRawHTML: '<!-- foo -->'}} />

This could work with server-side rendering, fragments, and hydration by wrapping content similar to Suspense:

<!--F-->
<!-- foo -->
<!--/F-->

Bikeshed me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment