Reputation: 181
When I click on the Login
button tried to make go to the Login Form page but right now it's not doing anything and I cannot figure how to use console.log
so I can debug my code.
This homepage where Navigation is live and all the other components that will be displaying.
import React, { Component } from "react"
import history from '../history';
import Navigation from '../../layouts/navigation';
export default class Home extends Component {
componentDidMount() {
history.push('/home');
}
showLoginBox() {
this.setState({isLoginOpen: true, isRegisterOpen: false});
}
showRegisterBox() {
this.setState({isRegisterOpen: true, isLoginOpen: false});
}
render() {
return (
<div id="home">
<Navigation showRegisterBox={this.showRegisterBox.bind(this)} showLoginBox={this.showLoginBox.bind(this)}/>
</div>
);
}
}
This is where the form is going to live at:
import React from 'react';
import RegisterBox from '../Forms/Register'
import LoginBox from '../Forms/Login'
// This is the page for form to live on
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoginOpen: true,
isRegisterOpen: false
};
}
render() {
return (
<div>
<div className="root-container">
{this.state.isLoginOpen && <LoginBox/>}
{this.state.isRegisterOpen && <RegisterBox/>}
</div>
</div>
)
}
}
export default App;
This is where Navigation buttons of Login and Sign up is live
import React from 'react';
import { BrowserRouter as Router, Link } from 'react-router-dom';
import "../components/pages/Forms/MainScreen";
import Dropdown from "../components//pages/dropdowns/dropdowns";
import hamburger from "../images/menu.svg"
class Navigation extends React.Component {
constructor(props) {
super(props);
this.state = {
isExpanded: false
};
}
handleToggle(e) {
e.preventDefault();
this.setState(prevState => ({
isExpanded: !prevState.isExpanded, // negate the previous expanded state
}));
}
showLoginBox() {
this.setState({isLoginOpen: true, isRegisterOpen: false}); // The Logic form will show when the users click the login button
}
showRegisterBox() {
this.setState({isRegisterOpen: true, isLoginOpen: false}); // The Signup form will show when the users click the login button
}
render() {
const { isExpanded } = this.state;
return (
<Router>
<div className="NavbarContainer">
<div className="mobilecontainer LeftNav">
<h2 className="BrandName LeftNav mobileboxmenu inline FarRight">Kommonplaces</h2>
<div className="hamburger inlinev" >
<img
onClick={e => this.handleToggle(e)}
alt="menubtn"
src={hamburger}
/>
</div>
</div>
<ul className={`NavBar collapsed ${isExpanded ? "is-expanded" : ""}`}>
<Dropdown/>
<li className="RightNav"><Link to="/">Host Your Space</Link></li>
<li className="RightNav"><Link to="/">About Us</Link></li>
<li className="RightNav"><Link to="/">Contact Us</Link></li>
<div className="btnflexright">
<button
className={"controller " + (this.state.isLoginOpen
? "selected-controller"
: "")}
onClick={this
.props
.showLoginBox}>
Login
</button>
<button
className={"controller " + (this.state.isRegisterOpen
? "selected-controller"
: "")}
onClick={this
.props
.showRegisterBox}>
Sign up
</button>
</div>
</ul>
</div>
</Router>
);
}
}
export default Navigation;
This one my code for forms but of them all the same:
//Login Box
import React from 'react';
class LoginBox extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
render() {
return (
<div>
<div className="formContent modal-main">
<h2>Welcome Back <span>Brandon!</span></h2>
<form>
<input
type="text"
name="email"
placeholder="Email Address"
/>
<input
name="password"
type="text"
placeholder="Password"
/>
<div className="passContent">
<div className="checkingPass">
<input
className="inline"
type="checkbox"
name="check"
value="Remember Password"
/>
<span
className="inline">
Remember Password
</span>
</div>
<p
className="passFont">
Forgot Password
</p>
</div>
<input
className="formmbtn"
type="button"
name="button"
alue="Login"
/>
<div
className="social-media-button">
<input
className="clearbtn"
type="button"
name="button"
value="Sign in with Facebook"
/>
<div
className="divider"
/>
<input
className="clearbtn"
type="button"
name="button"
value="Sign in with Facebook"
/>
</div>
<p
className="passFont">
Don't have an account?
<span>Sign up</span>
</p>
</form>
</div>
</div>
)
}
}
export default LoginBox;
Upvotes: 0
Views: 86
Reputation: 9779
You can console any where inside component except inside returning jsx and if you want inside jsx that is also possible like this
return(
<>
{console.log('inside return')}
<>
)
inside render
render(){
console.log('Inside return')
return(
<>
Hello
<>
)
}
inside constructor
constructor(props){
super(props)
console.log('Inside constructor')
}
inside your login function
showLoginBox() {
console.log('login function clicked');
this.setState({isLoginOpen: true, isRegisterOpen: false});
}
Upvotes: 1