A successor of react-proxy, created especially for react-hot-loader case. From API point of view - this is react-proxy.
The differences from react-proxy:
React stand in is a real stand in. To satisfy goal it:
real method in prototypeupgrade list.The keys points from here, you should keep in mind.
first class, and next
upgrating it to the last one. There is no way to replace constructor for ES6
classes.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.
You will need something like react-deep-force-update to re-render the component tree after applying the update.
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)
// Will reset state and kill DOM :-(
React.render(<ComponentVersion2 />, rootEl)
With React Facade:
import React from 'react'
import { render } from 'react-dom'
import createProxy from 'react-stand-in'
import deepForceUpdate from 'react-deep-force-update'
// Create a proxy object, given the initial React component class.
const proxy = createProxy(ComponentVersion1)
// Obtain a React class that acts exactly like the initial version.
// This is what we'll use in our app instead of the real component class.
const Proxy = proxy.get()
// Render the component (proxy, really).
const rootInstance = render(<Proxy />, rootEl)
// Point the proxy to the new React component class by calling update().
// Instances will stay mounted and their state will be intact, but their methods will be updated.
proxy.update(ComponentVersion2)
// Force-update the whole React component tree.
// Until React provides an official DevTools API to do this,
// you should keep the reference to the root instance(s).
deepForceUpdate(rootInstance)
displayNametoString() of methodssetInterval or setTimeout are updatedthis.constructor to match the most recent classMIT