我在类组件中的代码
我仍然是学习 React 的新手,我很难将类组件转换为功能组件。
class App extends React.Component {
handleChange = (e) => {
const { name, value } = e.target
this.setState({
[name]: value
})
}
configureCaptcha = () => {
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('sign-in-button', {
'size': 'invisible',
'callback': (response) => {
this.onSignInSubmit();
console.log("Recaptca varified")
},
defaultCountry: "IN"
});
}
onSignInSubmit = (e) => {
e.preventDefault()
this.configureCaptcha()
const phoneNumber = "+91" + this.state.mobile
console.log(phoneNumber)
const appVerifier = window.recaptchaVerifier;
firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier)
.then((confirmationResult) => {
window.confirmationResult = confirmationResult;
console.log("OTP has been sent")
}).catch((error) => {
console.log("SMS not sent")
});
}
render() {
.....
)
}
}
export default App;
我在 Component 类中的输出
如何在 reactjs 中使用钩子将类组件转换为函数组件