React Native问题:插入空行
在 React 中测试了一些东西,并发现我的一些逻辑存在一些问题。我试图从表单中的输入中获取值,然后在提交该表单时我想获取该输入值对象并将它们添加到我的工厂状态中。当我控制台日志时,我得到状态值,但植物状态为空。任何帮助表示赞赏。
谢谢
const [plant, setPlant] = useState();
const [TypeofPlant, setType] = useState('')
const [Phase, setPhase] = useState('')
const [Days, setDay] = useState(null)
const [Start, setStart] = useState(0)
const [End, setEnd] = useState(0)
const handleSubmit = async (e) => {
e.preventDefault()
setPlant({...plant,
TypeofPlant: TypeofPlant,
Phase: Phase,
Days: Days,
Start: Start,
End: End,
})
DataService.addNewPlant(plant).then(() => {
})
},
(error) => {
console.log(error)
}
);
数据服务:
addNewPlant(data){
return http.post('/plants/add',data)
}
Testing some things in React and having some issues with some of my logic. I am trying to get value from inputs in a form then on submitting that form I want to take that object of input values and add them to my plant state. When I console log I get the state values but then the plant state is empty. Any help is appreciated.
Thank you
const [plant, setPlant] = useState();
const [TypeofPlant, setType] = useState('')
const [Phase, setPhase] = useState('')
const [Days, setDay] = useState(null)
const [Start, setStart] = useState(0)
const [End, setEnd] = useState(0)
const handleSubmit = async (e) => {
e.preventDefault()
setPlant({...plant,
TypeofPlant: TypeofPlant,
Phase: Phase,
Days: Days,
Start: Start,
End: End,
})
DataService.addNewPlant(plant).then(() => {
})
},
(error) => {
console.log(error)
}
);
DataService:
addNewPlant(data){
return http.post('/plants/add',data)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在 DataService 块之外对工厂进行控制台。
Try to console plant outside of DataService block.
Response.json() 方法接口采用响应流并读取它完成。它返回一个承诺,该承诺将正文文本解析为 JSON 的结果进行解析。
更新代码如下
The Response.json() method interface takes a Response stream and reads it to completion. It returns a promise which resolves with the result of parsing the body text as JSON.
Update the code like below