简体   繁体   English

我的反应组件没有显示,尽管没有错误

[英]My react component is not displaying despite having no errors

So i have zero errors, all my other components are displaying except my SignUp component. 所以我的错误为零,除“我的注册”组件外,所有其他组件都在显示。 if I purposely create an error in the jsx of the SignUp component it will give me an error which makes me believe that the component is being rendered but its just not displaying on the screen. 如果我故意在SignUp组件的jsx中创建一个错误,它将给我一个错误,使我相信该组件正在呈现,但它并未显示在屏幕上。 below ill provide the SignUp.js file, SignUp.css file and the App.js file. 下面将提供SignUp.js文件,SignUp.css文件和App.js文件。 thanks for your help. 谢谢你的帮助。

SignUp.js SignUp.js

import React, {Component} from 'react';
import '../stylesheets/SignUp.css';
import Auth from '../auth.js';
import NavBar from './NavBar.js';


const ENTER = 13;

var newAuth = new Auth();

class SignUp extends Component {

  _validatePassword=(password,passwordConfirm)=>{
    var lengthy = password.length < 6
    var samePassword = password !== passwordConfirm
    if(lengthy || samePassword){
      return false
      }
      else{
        return true
      }
    }
  _validateEmail=(email)=>{
    // var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    // return re.test(email)
  }
  _findError(email,password){
    return{
      email: email,
      password: password
    }
  }

  _handleSignup = () => {
    var user = {
      name:this.refs.fullname.value,
      email:this.refs.email.value,
      password:this.refs.password.value
    }
    if (user.name && user.email && user.password) {
      newAuth.signUp(user)
      .then(res => this.props.router.push('/login'))
      .catch(console.error);
    }
    else {
      this.setState({error: "Please fill in all fields"});
    }
  }




  _handleTyping = (e) => {
    if (this.state && this.state.error) {
      this.setState({ error: null })
    }
    if (e.keyCode===ENTER) {
      this._handleSignup()
    }
  }



  render(){
    return(

      <div className="signup">
       <NavBar/>
        <div className="group">
          <input className="page-input" type="text" ref="fullname"
            onKeyUp={this._handleTyping}
          />

          <span className="highlight"></span>
          <span className="bar"></span>
          <label className="modal-label">Full Name</label>
        </div>
        <div className="group">
          <input className="page-input" type="text" ref="email"
            onKeyUp={this._handleTyping}
          />
          <span className="highlight"></span>
          <span className="bar"></span>
          <label className="modal-label">Email</label>
        </div>
        <div className="group">
          <input className="page-input" type="password" ref="password"
            onKeyUp={this._handleTyping}
          />
          <span className="highlight"></span>
          <span className="bar"></span>
          <label className="modal-label">Password</label>


        </div>
        <div className="group">
          <input className="page-input" type="password" ref="passwordConfirm"
            onKeyUp={this._handleTyping}
          />
          <span className="highlight"></span>
          <span className="bar"></span>
          <label className="modal-label">Confirm Password</label>

          <button className="signup-btn" onClick={this._handleSignup}><span>Sign Up</span></button>

        </div>

       {this.state && this.state.error ?
          <p>{this.state.error}</p>
          : null
        }
      </div>

    )
  }
}
export default SignUp;

SignUp.css SignUp.css

.singup {
  display: flex;
  flex-direction: column;
  height: 350px;
  margin-top: 55px;
}


.page-input                 {
  font-size:18px;
  padding:10px 10px 10px 5px;
  display:block;
  width:190px;
  border:none;
  border-bottom:1px solid #757575;
}
.page-input:focus       { outline:none; }

.page-input:focus ~ label, .page-input:valid ~ label        {
  top:-20px;
  font-size:14px;
}

label                {
  transition:0.2s ease all;
  -moz-transition:0.2s ease all;
  -webkit-transition:0.2s ease all;
}

.bar    { position:relative; display:block; width:190px; }
.bar:before, .bar:after     {
  content:'';
  height:2px;
  width:0;
  bottom:1px;
  position:absolute;
  background:black;
  transition:0.2s ease all;
  -moz-transition:0.2s ease all;
  -webkit-transition:0.2s ease all;
}
.bar:before {
  left:50%;
}
.bar:after {
  right:50%;
}

.page-input:focus ~ .bar:before, .page-input:focus ~ .bar:after {
  width:50%;
}
.group{
  display: flex;
  flex-direction: column;
  align-items: center;

}
highlight {
  position:absolute;
  height:60%;
  width:200px;
  top:25%;
  left:0;
  pointer-events:none;
  opacity:0.5;
}

.page-input:focus ~ .highlight {
  -webkit-animation:.page-inputHighlighter 0.3s ease;
  -moz-animation:.page-inputHighlighter 0.3s ease;
  animation:.page-inputHighlighter 0.3s ease;
}

.signup-btn {
  position: relative;

  display: block;
  /*margin: 30px auto;*/
  margin-top:50px;
  padding: 0;

  overflow: hidden;

  border-width: 0;
  outline: none;
  border-radius: 2px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .6);

  background-color: #2ecc71;
  color: #ecf0f1;

  transition: background-color .3s;
}

.signup-btn:hover, .signup-btn:focus {
  background-color: #27ae60;
}

.signup-btn > * {
  position: relative;
}

.signup-btn span {
  display: block;
  padding: 12px 24px;
}

.signup-btn:before {
  content: "";

  position: absolute;
  top: 50%;
  left: 50%;

  display: block;
  width: 0;
  padding-top: 0;

  border-radius: 100%;

  background-color: rgba(236, 240, 241, .3);

  -webkit-transform: translate(-50%, -50%);
  -moz-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  -o-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

.signup-btn:active:before {
  width: 120%;
  padding-top: 120%;

  transition: width .2s ease-out, padding-top .2s ease-out;
}

App.js App.js

import React, { Component } from 'react';
import DietPlan from './components/DietPlan.js';
import LoseWeight from './components/LoseWeight.js';
import SignUp from './components/SignUp.js';
import FrontPage from'./components/FrontPage.js';
import LogIn from'./components/LogIn.js';
import BuildMuscleForm from'./components/BuildMuscleForm';
import {Route} from"react-router";
import {BrowserRouter} from"react-router-dom";

class App extends Component {
  render() {
    return (
      <BrowserRouter>
      <div>
        <Route exact path={"/"} component={FrontPage}/>
        <Route path={"/singup"} component={SignUp}/>
        <Route path={"/login"} component={LogIn}/>
        <Route path={"/buildmuscle"} component={BuildMuscleForm}/>
        <Route path={"/loseweight"} component={LoseWeight}/>
        <Route path={"/planning"} component={DietPlan}/>



      </div>
      </BrowserRouter>

    );
  }
}

export default App;

im pretty stumped as to whats going on here because every other component is display. 我很困惑这里发生了什么,因为显示了其他所有组件。 all im getting is a blank page and no errors. 即时通讯是空白页,没有错误。 it could be something really simple that i didnt notice. 我可能没有注意到这可能是非常简单的事情。 thanks for the help 谢谢您的帮助

App.js defines the following route: App.js定义以下路线:

<Route path={"/singup"} component={SignUp}/>

Which specifies the path for the SignUp component to be '/singup' instead of '/signup' SignUp组件的路径指定为'/singup'而不是'/signup'

If you correct the typo you should be able to see your component - you could also omit the curly braces 如果您纠正了错字,您应该可以看到您的组件-您也可以省略花括号

<Route path="/signup" component={SignUp} />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的反应组件没有使用路由显示 - My react component is not displaying using routes React Component 没有显示不同的文本/信息,尽管被赋予了唯一的对象作为传递的道具 - React Component not displaying different text / information despite being given unique objects as passed props 我的CSS样式表对我的React组件没有影响 - My CSS style sheet is having no impact on my React component 在我的 React 组件中获取 react-modal 的错误 - Errors getting react-modal in my React Component 为什么反应文本组件不显示对我的数组 state 的更新 - Why is the react text component not displaying updates to my array state 微调器不显示在反应组件上 - Spinner not displaying on react component 在 React.js 中设置组件状态时遇到问题 - Having trouble with setting the state in my component in React.js 我在将主干集合传递到React组件时遇到麻烦 - I am having trouble passing in my backbone collection in to a react component 反应组件错误(输入) - React Component errors (Input) 尽管在我的控制台中成功编译,为什么我的反应应用程序在导入和使用材料 ui 中的图标后显示空白屏幕? - Why is my react app displaying a blank screen after importing and using an icon from material ui despite compiling successfully in my console?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM