Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-box

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-box

Wraps repeatedly rerendered components preserving their nodes in real DOM to reduce paints

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source

React Box

Wraps repeatedly rerendered components preserving their nodes in real DOM to reduce paints. The idea is borrowed from Noscript framework, where box is a container for views that manages visibility of active views instead of taking irrelevant nodes out of DOM.

Installation

npm install react-box

Usage

Wrap your content into Box element, and make sure that children of different classes have distinct keys:

render: function() {
    var content;

    if (this.props.mode === 'map') {
        content = <Map key='map' />;
    } else {
        content = <Post key='post' id={ this.props.id } />
    }

    return <Box>{ content }</Box>;
}

This example will result in the following HTML structure:

<!-- Initial render: <Content mode='map' /> -->
<div>
    <div style="display: block;">
        <div class="map"><!-- … --></div>
    </div>
</div>

<!-- First update: <Content mode='post' id='1' /> -->
<div>
    <div style="display: none;">
        <div class="map"><!-- … --></div>
    </div>
    <div style="display: block;">
        <div class="post">
            <h1>Post ID: 1</h1>
            <!-- … -->
        </div>
    </div>
</div>

<!-- Second update: <Content mode='post' id='2' /> -->
<div>
    <div style="display: none;">
        <div class="map"><!-- … --></div>
    </div>
    <div style="display: none;">
        <div class="post">
            <h1>Post ID: 1</h1>
            <!-- … -->
        </div>
    </div>
    <div style="display: block;">
        <div class="post">
            <h1>Post ID: 2</h1>
            <!-- … -->
        </div>
    </div>
</div>

<!-- Third update: <Content mode='post' id='2' /> -->
<div>
    <div style="display: block;">
        <div class="map"><!-- … --></div>
    </div>
    <div style="display: none;">
        <div class="post">
            <h1>Post ID: 1</h1>
            <!-- … -->
        </div>
    </div>
    <div style="display: none;">
        <div class="post">
            <h1>Post ID: 2</h1>
            <!-- … -->
        </div>
    </div>
</div>

Keywords

FAQs

Package last updated on 28 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc