Skip to content

Instantly share code, notes, and snippets.

@async3619
Last active April 5, 2018 04:40
Show Gist options
  • Save async3619/3a22fa737658b257212d9a86aa855503 to your computer and use it in GitHub Desktop.
Save async3619/3a22fa737658b257212d9a86aa855503 to your computer and use it in GitHub Desktop.
Integrate react.js on existing php webpages
import React from 'react';
import ReactDOM from 'react-dom';
const entries = {
"#login": () => import(/* webpackChunkName: "login" */ "./login.js"),
// ^^^^^ this chunk will be created as "login.js".
// and then we can add dom element "#login" and import bundle.js and login.js when we want to use `Login` component.
};
Object.keys(entries).some(selector => {
const rootContainer = document.querySelector(selector);
if (!rootContainer) return false;
entries[selector]().then(({ default: Component }) => {
ReactDOM.render(<Component />, rootContainer);
});
return true;
});
import React, { Component } from 'react';
class Login extends Component {
render() {
return (
<div>
Hello
</div>
);
}
}
export default Login;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment