I have a basic form that includes two text inputs and one button using a project created from the react native CLI.
const Signup = () => {
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const handleChangeUsername = () => {
setUsername(username)
}
const handleChangePassword = () => {
setPassword(password)
}
const btnSignup = () => {
// auth()
// .createUserWithEmailAndPassword(setUsername,setPassword)
// .then(() => {
// console.log('User account created & signed in!');
// })
}
return (
<View>
<View>
<TextInput onChangeText={handleChangeUsername}> Kullanıcı Adı </TextInput>{' '}
<TextInput onChangeText={handleChangePassword}> Password </TextInput>{' '}
</View>{' '}
<View>
{' '}
<Button onPress={btnSignup} title="TIKLA" />{' '}
</View>
</View>
)
}
export default Signup
I can’t use the btnSignup
method because when it’s run give an error. What is the issue here?
2
Answers
Id replace your text inputs as the below
I then get no errors when clicking button. If youre trying to console log the username write console.log(username) instead of console.log(setUsername)
function. If you want to log the value you need to write:
console.log(username)
handleChangePassword to receive input value and update state which
would look like this:
const handleChangeUsername = (value) => { setUsername(value); }
and if you want to log username nad password you can do it inside btnSignup which would look like this: