im new in react native and i try to passing data from my login class to a auth function but it dont work.
This is my Auth function
function auth(username, password) {fetch('http://192.168.178.26:8000/auth/', { method: 'POST', headers: {'Content-Type': 'application/json', }, body: JSON.stringify({ username, password })}) .then(res => res.json()) .then(res => { saveToken(res.token); console.log(res.token); props.navigation.navigate('Home'); }) .catch(error => console.log(error));
Constructor
constructor() { super() this.state = { isReady: false, username: '', password: '', } this.auth = auth(this.state.username, this.state.password)...more code render() { const {password} = this.state.password; const {username} = this.state.username;
My Text Inputs and the login button
<TextInput placeholder='Email' ... value={username}/><TextInput placeholder='Password' ... value={password}/><TapGestureHandler><Animated.View style={style.button} ><Text style={{ ... onPress={this.auth}>Anmelden</Text>
I work on this for days now and googled hours but i cant find a solution. Can you please help me?
Best regards.