如何将数据从row
传递到handleSubmit
即
const handleSubmit = async (e) => {
e.preventDefault();
// do something with row data but how do I even get it here??
setExampleData(row.original.ExampleData) //this does not work
}
renderDetailPanel={({ row }) => (
//blah blah code, no idea where to take row to put into the function
<Button onClick={handleSubmit}>Action something to {row.original.info}</Button>
)
我尝试将其放入renderDetailPanel中的一个表单槽中,但控制台显示为未定义。例如:
renderDetailPanel={({ row }) => (
//I put it here and hoped for the best but nothing came of it
<TextField
autoFocus
margin="dense"
id="message"
value={message}
label="Message"
onChange={(e) => {
setMessage(e.target.value);
setExampleData(row.original.ExampleData); //over here
}}
/>
<Button onClick={handleSubmit}>Action something to {row.original.info}</Button>
)
1条答案
按热度按时间oxcyiej71#
一个可能的解决方案是将
row
作为参数添加到handleSubmit()
函数中:然后使用
onClick
处理程序的匿名函数将row
传递给handleSubmit()
: