InputField
& Button
कस्टम घटक हैं जो फ़ॉर्म बनाने के लिए एक रूप में जाते हैं। मेरे मुद्दा है मैं डेटा वापस ऊपर भेजूँ कैसे इतना है कि बटन पर क्लिक के रूप में, मैं डेटा के साथ प्रपत्र (उपयोगकर्ता नाम & पासवर्ड) पर ajax आग कर सकते हैं:प्रतिक्रिया - क्या एक बाल घटक मूल्य पत्र को वापस भेज सकता है
export default auth.authApi(
class SignUpViaEmail extends Component{
constructor(props){
super(props);
this.state = {
email : "",
password : ""
};
this.storeEmail = this.storeEmail.bind(this);
this.storePassword = this.storePassword.bind(this);
}
storeEmail(e){
this.setState({ email : e.target.value });
}
storePassword(e){
this.setState({ password : e.target.value });
}
handleSignUp(){
this.props.handleSignUp(this.state);
}
render(){
return(
<div className="pageContainer">
<form action="" method="post">
<InputField labelClass = "label"
labelText = "Username"
inputId = "signUp_username"
inputType = "email"
inputPlaceholder = "registered email"
inputClass = "input" />
<Button btnClass = "btnClass"
btnLabel = "Submit"
onClickEvent = { handleSignUp } />
</form>
</div>
);
}
}
);
या यह अनुशंसित नहीं है & मैं नहीं करना चाहिए फॉर्म के भीतर कस्टम बाल घटक बनाएँ?
बच्चे घटक =>InputField
import React,
{ Component } from "react";
export class InputField extends Component{
constructor(props){
super(props);
this.state = {
value : ""
};
this.onUserInput = this.onUserInput.bind(this);
}
onUserInput(e){
this.setState({ value : e.target.value });
this.props.storeInParentState({[ this.props.inputType ] : e.target.value });
}
render(){
return <div className = "">
<label htmlFor = {this.props.inputId}
className = {this.props.labelClass}>
{this.props.labelText}
</label>
<input id = {this.props.inputId}
type = {this.props.inputType}
onChange = {this.onUserInput} />
<span className = {this.props.validationClass}>
{ this.props.validationNotice }
</span>
</div>;
}
}
त्रुटि: मैं माता पिता storeEmail समारोह पर त्रुटि e.target is undefined
मिलता है।
आप इनपुट में 'कीप' ईवेंट हैंडलर पास कर सकते हैं ताकि मूल घटक स्थिति लगातार अद्यतित हो। फिर जब भी संभालती है सिग्नल को फॉर्म घटक कहा जाता है, उसके पास पहले से ही सब कुछ है। – theleebriggs
@ rufio86 सही है, आपको पहले अपने मूल घटक स्थिति को अपडेट करने की आवश्यकता है। और आपको 'हैंडल सिग्नलअप' कॉलबैक बांधना होगा, फिर आपको अपना स्टेटस मिल जाएगा। – hawk
@ rufio86 और hawk दोनों के लिए क्षमा करें, कृपया – Kayote