我是歌谣 微信公众号关注前端小歌谣进入前端巅峰人才交流群
import * as React from 'react';
import {Button,Typography,Box} from '@mui/material';
import { Create,useNotify, SimpleForm, TextInput, DateInput, required,TopToolbar} from 'react-admin';
const PostCreateActions = () => (
<TopToolbar>
{/* Add your custom actions */}
<Button color="primary">geyao</Button>
</TopToolbar>
);
const Aside = () => (
<Box sx={{ width: '200px', margin: '1em' }}>
<Typography variant="h6">Instructions</Typography>
<Typography variant="body2">
Posts will only be published once an editor approves them
</Typography>
</Box>
);
export const RcreateAdd = () => {
const notify = useNotify();
const onSuccess = (data) => {
notify(`Changes saved`);
};
const transform = data => ({
...data,
name: `${data.name} ${data.sex}`
});
return(
<Create transform={transform} mutationOptions={{ onSuccess }} disableAuthentication component="div" actions={<PostCreateActions />} aside={<Aside />}>
<SimpleForm>
<TextInput source="name" validate={[required()]} fullWidth />
<TextInput source="sex" multiline={true} label="Short description" />
<TextInput source="salary" multiline={true} label="Short description" />
</SimpleForm>
</Create>
)
}
运行结果 一个函数将记录作为参数,并返回修改后的记录