Please help need to insert variable into the return
export default function AboutScreen({ route }) {
const { name } = route.params;
alert(name)
state = {
text: '',
stored1Value: '',
storedValue: '',
store1Value: '',
storeValueU: '',
storeValueUU: '',
storeValueUUU: '',
storeValueUUUU: '',
storeValueUUUUU: '',
}
axios.get('https://cookiebytes.ca/google-login-php/Jacob.php?name=' + name)
.then(response => {
alert(response.data)
})
.catch(error => {
console.log(error)
});
return (
<View>
<Text>AboutScreen {response}</Text>
</View>
);
}
How to get the variable from the response into the return ?!
2
Answers
You should use state to store the response data and then render it.
I used
useEffect
to perform the Axios request when the component mounts or when the name parameter changes. The response data is stored in the response state variable and then displayed in the Text component within the return statement.Instead of the
You are using now, you will want to create an object that matches the return type.
So, if, for example, the return is a string:
And then in your get call
And then you can access the data in the return state variable.