React: render the component

0 votes
281 views
added Aug 18, 2017 in React by LC Marshal Captain (25,790 points)
edited Jul 13, 2018 by LC Marshal

Example directory: 

  • Yoursite/template/layout/index.html
  • Yoursite/js/app.js
  • Yoursite/js/components/header/header.js

Index.html

<body>
   <header id="header"></header>
</body>

app.js

import Header from './components/headers/header'

window.addEventListener('DOMContentLoaded', () => {
const project_store = new Project()

if($('#header').length) {
ReactDOM.render(<Header />, document.getElementById('header'))
}
})

header.js

import { Component } from 'react'
class Header extends Component {
  render() {
  return (
    <div>
      Header element goes here
    </div>
  )
  }
}
module.exports = Header
lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...