I am using react to build a signin and register form. In a signin component when I try to post some data using fetch to my database then I should receive a response from the server. So I try to console that promise(response). But the problem is, promise can be seen for a fraction of second in the console but suddenly it disappears. Actually, I am new to react so am not getting why is this happening...
The surprising thing is I am using fetch in the same way in the register component also but there everything is fine. And my server is also working fine as I have checked it using POSTMAN.
here is my code of signin component
import React from 'react';
class Signin extends React.Component{
constructor(props){
super(props);
this.state={
signInEmail:'',
signInPassword:''
}
}
onEmailChange=(event)=>{
this.setState({signInEmail:event.target.value})
}
onPasswordChange=(event)=>{
this.setState({signInPassword:event.target.value})
}
onSubmitSignIn=()=>{
const prom= fetch('http://localhost:3001/signin',{
method:'post',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({
email:this.state.signInEmail,
password:this.state.signInPassword
})
})
console.log(prom);
}
render(){
const {onRouteChange}=this.props;
return (
<div>
<article className="br3 ba dark-grey mv4 w-100 w-50-m w-25-l mw6 shadow-5 center">
<main className="pa4 black-80">
<form className="measure">
<fieldset id="sign_up" className="ba b--transparent ph0 mh0">
<legend className="f1 fw6 ph0 mh0">Sign In</legend>
<div className="mt3">
<label className="db fw6 lh-copy f6" htmlFor="email-address">Email</label>
<input onChange={this.onEmailChange}
className="pa2 input-reset bg-transparent hover-bg-black hover-white w-100"
type="email"
name="email-address"
id="email-address"
/>
</div>
<div className="mv3">
<label className="db fw6 lh-copy f6" htmlFor="password">Password</label>
<input onChange={this.onPasswordChange}
className="b pa2 input-reset bg-transparent hover-bg-black hover-white w-100"
type="password"
name="password"
id="password"
/>
</div>
</fieldset>
<div className="">
<input onClick={this.onSubmitSignIn}
className="b ph3 pv2 input-reset ba b--black bg-transparent grow pointer f6 dib"
type="submit"
value="Sign in"
/>
</div>
<div className="lh-copy mt3">
<p onClick={() => onRouteChange('Register')} className="f6 link dim black db pointer">Register</p>
</div>
</form>
</main>
</article>
</div>
);
}
}
export default Signin;