When i try to integrate with mutation using apollo i got this error Objects are not valid as a React child (found: [object Error]). If you meant to render a collection of children, use an array instead react native
src/Mutation
export const SIGNIN_USER = gql mutation signinUser($usersignin:UserSigninInput!) { user:signinUser(userSignin:$usersignin) { token } }
src/Login.js
const Login = (props) => {
const [values, setValues] = useState({ email: '', password: '' });
const [signinUser,{error,loading,data}] = useMutation(SIGNIN_USER)
if (loading) return <Text>Loading... 🚀</Text>
if (error) return <Text>{error}</Text>
const handleChange = (name, value) => {
setValues({
...values,
[name]: value,
});
};
const handleSubmit = () => {
console.log("values are ==>",values)
signinUser({
variables: {
userSignin: values
}
})
}
return (
<View style={styles.container}>
<View style={styles.titleView} >
<Text style={styles.title}>Login</Text>
</View>
<View style={{ height: hp('5%') }}></View>
<TextInput placeholder='Please Enter Email' style={styles.textInput} onChangeText={(text) => handleChange('email', text)}
value={values.firstName} />
<TextInput secureTextEntry={true} placeholder='Please Enter Password' style={styles.textInput} onChangeText={(text) => handleChange('password', text)} />
<TouchableOpacity style={styles.buttonView} onPress={handleSubmit} >
<Text style={styles.btnText}>Signin</Text>
</TouchableOpacity>
</View>
)
}
错误:对象作为React子级无效(找到:如果您想呈现一个子集合,请使用数组来代替。我的代码中有什么错误?对象作为React子对象无效(找到:[对象错误])。如果您打算呈现子级集合,请改用数组
1条答案
按热度按时间q8l4jmvw1#
值应为
value={values.email}
,如下所示: