Reputation: 91
Some thing wrong with my code:
import React from 'react';
import {Link} from 'react-router';
import CurrentUser from './../services/current-user.js';
import HeaderWithoutLogin from './header-without-login.js';
import HeaderWithLogin from './header-with-login.js';
let Header = React.createClass({
render: () => {
var Child = CurrentUser.isLoggedIn()
? HeaderWithLogin
: HeaderWithoutLogin;
return <div>{Child}</div>;
}
});
export default Header;
import React from 'react';
import {Link} from 'react-router';
import CurrentUser from './../services/current-user.js';
import HeaderWithoutLogin from './header-without-login.js';
import HeaderWithLogin from './header-with-login.js';
let Header = React.createClass({
render: () => {
if (CurrentUser.isLoggedIn()) {
return <HeaderWithLogin/>;
}
return <HeaderWithoutLogin/>;
}
});
export default Header;
How I need use my logic? I mean return and render different views regarding the statement
Upvotes: 0
Views: 179
Reputation: 47222
Your render
method within HeaderWithLogin
is not correct.
render: () => {}
will try to bind this
to something totally different from what you're expecting, which will produce undefined
.
Change to this and it'll work.
render() {}
or ES5 equivalent
render: function () {}
Upvotes: 1