reactjs - React-Admin I 自定义按钮无法获取表单数据
问题描述
我创建了一个自定义按钮来拒绝用户。我想发送拒绝但无法发送表单数据的原因。我在 userEdit 组件中使用“FormWithRedirect”。
import React from 'react';
import PropTypes from 'prop-types';
import { makeStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import ThumbDown from '@material-ui/icons/ThumbDown';
import { useUpdate, useNotify, useRedirect } from 'react-admin';
/**
* This custom button demonstrate using a custom action to update data
*/
const useStyles = makeStyles((theme) => ({
button: {
color: 'red',
borderColor: 'red',
"&:hover": {
color: '#fff',
background: 'red',
borderColor: 'red',
}
},
}));
const RejectButton = ({ record }: any) => {
const notify = useNotify();
const redirectTo = useRedirect();
const classes = useStyles();
const [reject, { loading }] = useUpdate(
`users/${record.id}/_reject`,
'',
{ reason: 'Due to missinng information or may be the license picture is not visible. Please upload again.' },
record,
{
undoable: true,
onSuccess: () => {
notify(
'User profile rejected!',
'info',
{},
true
);
redirectTo('/users');
},
onFailure: (error: any) => notify(`Error: ${error.error}`, 'warning'),
}
);
return (
<Button
variant="outlined"
color="primary"
size="small"
onClick={reject}
disabled={loading}
className={classes.button}
startIcon={<ThumbDown />}
>
Reject
</Button>
);
};
RejectButton.propTypes = {
record: PropTypes.object,
};
export default RejectButton;
这是我的rejectButton 组件代码,因此我发送静态值,但我想发送我在TextArea 组件中输入的任何内容。
解决方案
推荐阅读
- selenium - Selenium - 运行时的FB通知?
- javascript - JS reduceRight 导致数组成为对象,我该如何修复逻辑?
- jupyter-notebook - 在 jupyter notebook 上运行长代码的问题
- swift - 通过 electron-builder 嵌入 Finder Sync 扩展的问题
- reactjs - 反应路线不起作用,我不明白为什么
- visual-studio - Visual Studio 发布,不包括发布目录中的自定义 dll
- r - 如何使用特定列中的 ID 在 R 中 cbind data.frames
- c++ - 关于 ISupportErrorInfo::InterfaceSupportsErrorInfo() 实现的问题
- azure - 无法使用 ARM 模板创建带有 ip 的 azure private dns A 记录
- python - python vs-code在file.py目录下运行file.py