Last active
April 5, 2018 04:40
-
-
Save async3619/3a22fa737658b257212d9a86aa855503 to your computer and use it in GitHub Desktop.
Integrate react.js on existing php webpages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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