Giter Club home page Giter Club logo

react-dom-fragment's Introduction

React DOM Fragment PostCSS

NPM Version Build Status Support Chat

React DOM Fragment lets you create React Fragments that support dangerously setting their innerHTML without a container element.

import Fragment from 'react-dom-fragment';

<Fragment dangerouslySetInnerHTML={{ __html: '<h1>No containers here</h1>' }} />

React DOM Fragment patches DOM updates so that unchanged portions of your code won’t be re-created. Dynamic elements like video, images, and iframes will not reload, even as attributes update that do not change their source.

import Fragment from 'react-dom-fragment';

<Fragment
  dangerouslySetInnerHTML={{
    __html: `<strong>${'Ever-changing description of this video'}</strong>:
      <iframe src="https://www.youtube.com/watch?v=oHg5SJYRHA0" />' } />`
  }}
/>

Patching occurs at the deepest possible level without any container element so that even unchanged portions of Text Nodes are preserved.

<p>
  ...<Fragment dangerouslySetInnerHTML={{
    __html: Math.floor(Math.random() * 100)
  }} />...
</p>

/*
1st Pass (__html === 4):
  <p>
    "..."
    "4"
    "..."
  </p>

2nd Pass (__html === 45):
  <p>
    "..."
    "4"
    "5"
    "..."
  </p>

3rd Pass (__html === 50):
  <p>
    "..."
    "50"
    "..."
  </p>
*/

React DOM Fragment is still a React Fragment you can use as a drop-in replacement.

<Fragment>
  <p>Lorem ipsum.</p>
  <p>Dolar sit amet.</p>
</Fragment>

Usage

Add React DOM Fragment to your project:

npm install react-dom-fragment
import Fragment from 'react-dom-fragment';

<Fragment>A regular fragment</Fragment>
<Fragment dangerouslySetInnerHTML={{
  __html: 'Content parsed as <strong>HTML</strong>'
}} />

React DOM Fragment will increase your bundle size by up to 2.5kB when minified and gzipped.

react-dom-fragment's People

Contributors

loganarnett avatar jonathantneal avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.