Last active
December 8, 2016 17:02
-
-
Save quieterkali/4f51c8908d436a1de51e009f396d020b to your computer and use it in GitHub Desktop.
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
$ = jquery = require('jquery'); | |
((win) => { | |
'use strict'; | |
var React = require('react'); | |
var ReactDom = require('react-dom'); | |
var Home = require('./component/homePage'); | |
var About = require('./component/about/aboutPage'); | |
var Header = require('./component/common/header'); | |
var App = React.createClass({ | |
//se trocar essa function por arrow function, ela quebra bem no switch dizendo que nao pode ler a propriedade route de undefined | |
render: function() { | |
var Child; | |
console.log(this); | |
//output | |
/* | |
Object {props: Object, context: Object, refs: Object, updater: Object, state: null…} | |
*/ | |
switch(this.props.route){ | |
case 'about': Child = About; break; | |
default: Child = Home; | |
} | |
return ( | |
<div> | |
<Header /> | |
<Child /> | |
</div> | |
); | |
} | |
}); | |
function render() { | |
var route = win.location.hash.substr(1); | |
ReactDom.render(<App route={route} />, document.getElementById('app')); | |
} | |
win.addEventListener('hashchange', render); | |
render(); | |
})(window); | |
$ = jquery = require('jquery'); | |
((win) => { | |
'use strict'; | |
var React = require('react'); | |
var ReactDom = require('react-dom'); | |
var Home = require('./component/homePage'); | |
var About = require('./component/about/aboutPage'); | |
var Header = require('./component/common/header'); | |
var App = React.createClass({ | |
//se trocar essa function por arrow function, ela quebra bem no switch dizendo que nao pode ler a propriedade route de undefined | |
render: () => { | |
var Child; | |
console.log(this); | |
//output | |
/* | |
Object {} | |
*/ | |
switch(this.props.route){ | |
case 'about': Child = About; break; | |
default: Child = Home; | |
} | |
return ( | |
<div> | |
<Header /> | |
<Child /> | |
</div> | |
); | |
} | |
}); | |
function render() { | |
var route = win.location.hash.substr(1); | |
ReactDom.render(<App route={route} />, document.getElementById('app')); | |
} | |
win.addEventListener('hashchange', render); | |
render(); | |
})(window); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment