My Code in Class Component
I am still new to learning React and I am having a tough time converting class components into functional components.
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;
My output in class Component
how to convert class component to function component with hooks in reactjs