Skip to content

Commit

Permalink
Merge pull request #7206 from marmelab/avoid-cloning-elements-views
Browse files Browse the repository at this point in the history
Avoid cloning elements in Create and Edit views
  • Loading branch information
fzaninotto authored Feb 8, 2022
2 parents 6d2901d + 195aec5 commit a95aa2d
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 221 deletions.
45 changes: 5 additions & 40 deletions packages/ra-ui-materialui/src/detail/CreateView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Children, cloneElement, ReactElement } from 'react';
import { ReactElement } from 'react';
import PropTypes from 'prop-types';
import { Card } from '@mui/material';
import { styled } from '@mui/material/styles';
Expand All @@ -20,57 +20,22 @@ export const CreateView = (props: CreateViewProps) => {
...rest
} = props;

const {
defaultTitle,
record,
redirect,
resource,
save,
saving,
} = useCreateContext(props);
const { defaultTitle, record } = useCreateContext(props);

return (
<Root
className={classnames('create-page', className)}
{...sanitizeRestProps(rest)}
>
<Title title={title} record={record} defaultTitle={defaultTitle} />
{actions &&
cloneElement(actions, {
resource,
// Ensure we don't override any user provided props
...actions.props,
})}
{actions}
<div
className={classnames(CreateClasses.main, {
[CreateClasses.noActions]: !actions,
})}
>
<Content className={CreateClasses.card}>
{cloneElement(Children.only(children), {
record,
redirect:
typeof children.props.redirect === 'undefined'
? redirect
: children.props.redirect,
resource,
save:
typeof children.props.save === 'undefined'
? save
: children.props.save,
saving,
})}
</Content>
{aside &&
cloneElement(aside, {
record,
resource,
save:
typeof children.props.save === 'undefined'
? save
: children.props.save,
saving,
})}
<Content className={CreateClasses.card}>{children}</Content>
{aside}
</div>
</Root>
);
Expand Down
Loading

0 comments on commit a95aa2d

Please sign in to comment.