在React Native中插入具有TextInput值的数据,无法将默认值发送到API
我有一个具有textInput
's的屏幕。我正在尝试通过API将这些textInput
的值插入数据库。当提交而无需输入textInput
中时,我将使用textInput
中显示的值数据,但是在我的下面代码时,我会得到five>字段是必需
<代码>状态:422 。
const pressHandle = ({ name, userid }) => {
axios
.post(userPostLink, {
name,
userid,
})
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error.response);
});
};
<TextInput onChangeText={(text) => setUsername(text)} placeholder="username" value="steve" />
<TextInput onChangeText={(text) => setEventid(text)} placeholder="userid" value="fle91739" />
<TouchableOpacity onPress={() => pressHandle({ name, userid })}>
<Text style={{ color: "blue" }}>Submit</Text>
</TouchableOpacity>
I have a screen that has TextInput
's. I am trying to insert these TextInput
's values into the database through the API. And when submitted without typing in the TextInput
, I would use the value data that is showing in the TextInput
, but with my my below code I keep getting field is required
status: 422
.
const pressHandle = ({ name, userid }) => {
axios
.post(userPostLink, {
name,
userid,
})
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error.response);
});
};
<TextInput onChangeText={(text) => setUsername(text)} placeholder="username" value="steve" />
<TextInput onChangeText={(text) => setEventid(text)} placeholder="userid" value="fle91739" />
<TouchableOpacity onPress={() => pressHandle({ name, userid })}>
<Text style={{ color: "blue" }}>Submit</Text>
</TouchableOpacity>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您想更改JSX,使用
DefaultValue
来设置这些默认值。并将您的
PressHandle
更改为:First you would wanna change a little bit your JSX, make use of
defaultValue
for setting those defaults values.And change your
pressHandle
, to this: