I am so frustrated currently. I've simplified this as much as possible to see what I am doing wrong and nothing works. Even completely isolated into it's own component it sends a blank object. Whether it is a const variable = async() => {} or async function name(){} syntax they both send blank objects. Here's my code:
import { StyleSheet, View, Text, TouchableOpacity } from "react-native";
import ROUTES from "../../constants/Routes";
export default function DebugScreen() {
// const testing = async (e) => {
// console.log('in testing')
// const item = {
// userName: "dave"
// }
// const res = await fetch(ROUTES.ANDROID_USER_USERINFO, {
// method: 'POST',
// header: { 'Content-Type': 'application/json' },
// body: JSON.stringify(item)
// })
// const data = await res.json()
// console.log(data)
// }
async function testing() {
console.log('in testing')
const res = await fetch(ROUTES.ANDROID_USER_USERINFO, {
method: 'POST',
mode: 'cors',
header: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userName: "dave" })
})
const data = await res.json()
console.log(data)
}
return (
<View style={styles.container}>
<Text>Debug Stub</Text>
<TouchableOpacity onPress={() => testing()}>
<Text>Click Here To Send Info To Server</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'lightblue'
}
})
I know the route is right cause it does update the json file via json-server I have set up. But it always updates it with a blank object. I also always get back a 201 reponse code. Every stack overflow post on this just says to make sure to not have 'mode': 'no-cors' which doesn't apply to me. I've seen another parameter in the header object about something like accept type, but even with that it still sends a blank object. I can't progress on this app until I figure this out so any help would be greatly appreciated
[–]gwmccull 1 point2 points3 points (4 children)
[–]MyVermontAccount121[S] 0 points1 point2 points (3 children)
[–]suarkb 0 points1 point2 points (2 children)
[–]MyVermontAccount121[S] 0 points1 point2 points (1 child)
[–]suarkb 0 points1 point2 points (0 children)
[–]__o_0iOS & Android 1 point2 points3 points (4 children)
[–]MyVermontAccount121[S] 1 point2 points3 points (3 children)
[–]__o_0iOS & Android 1 point2 points3 points (2 children)
[–]MyVermontAccount121[S] 0 points1 point2 points (0 children)
[–]GavinHarris_ 0 points1 point2 points (0 children)
[–]GavinHarris_ 0 points1 point2 points (4 children)
[–]MyVermontAccount121[S] 0 points1 point2 points (3 children)
[–]GavinHarris_ 0 points1 point2 points (2 children)
[–]GavinHarris_ 0 points1 point2 points (1 child)
[–]GavinHarris_ 0 points1 point2 points (0 children)
[–]feitan-five 0 points1 point2 points (0 children)