JSPM

  • Created
  • Published
  • Downloads 136603
  • Score
    100M100P100Q151272F
  • License MIT

Proxies React components without unmounting or losing their state.

Package Exports

  • react-proxy
  • react-proxy/modules/index

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-proxy) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

React Proxy

Work in progress.

Generic React component proxy.
A future engine for React Hot Loader.

Usage

Intended to be used from hot reloading tools like React Hot Loader.
If you’re an application developer, it’s unlikely you’ll want to use it directly.

import React, { Component } from 'react';

class ComponentVersion1 extends Component {
  render() {
    return <div>Before hot update.</div>;
  }
}

class ComponentVersion2 extends Component {
  render() {
    return <div>After hot update.</div>;
  }
}

Without React Proxy:

const rootEl = document.getElementById('root');
React.render(<ComponentVersion1 />, rootEl);
React.render(<ComponentVersion2 />, rootEl); // will reset state and kill DOM :-(

With React Proxy:

import { createProxy } from 'react-proxy';

const proxy = createProxy(ComponentVersion1);
const Component = proxy.get();

React.render(<Component />, rootEl);
proxy.update(ComponentVersion2); // will keep the state and DOM

License

MIT