Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Improve form performance #3577

Merged
merged 2 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/simple/src/posts/PostCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
useRedirect,
useNotify,
} from 'react-admin'; // eslint-disable-line import/no-unresolved
import { useFormState } from 'react-final-form';
import { useFormState, FormSpy } from 'react-final-form';

const SaveWithNoteButton = props => {
const [create] = useCreate('posts');
Expand Down Expand Up @@ -128,17 +128,17 @@ const PostCreate = ({ permissions, ...props }) => {
<TextInput autoFocus source="title" />
<TextInput source="teaser" fullWidth={true} multiline={true} />
<RichTextInput source="body" validate={required()} />
<FormDataConsumer>
{({ formData, ...rest }) =>
formData.title && (
<FormSpy subscription={{ values: true }}>
{({ values }) =>
values.title ? (
<NumberInput
source="average_note"
defaultValue={5}
{...rest}
/>
)
) : null
}
</FormDataConsumer>
</FormSpy>

<DateInput
source="published_at"
defaultValue={dateDefaultValue}
Expand Down
8 changes: 8 additions & 0 deletions packages/ra-ui-materialui/src/form/SimpleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const SimpleForm = ({ initialValues, ...props }) => {
mutators={{ ...arrayMutators }}
keepDirtyOnReinitialize
destroyOnUnregister
subscription={defaultSubscription}
{...props}
render={({ submitting, ...formProps }) => (
<SimpleFormView
Expand All @@ -55,6 +56,13 @@ const SimpleForm = ({ initialValues, ...props }) => {
);
};

const defaultSubscription = {
submitting: true,
pristine: true,
valid: true,
invalid: true,
};

export default SimpleForm;

const SimpleFormView = ({
Expand Down
8 changes: 8 additions & 0 deletions packages/ra-ui-materialui/src/form/TabbedForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const TabbedForm = ({ initialValues, ...props }) => {
setRedirect={setRedirect}
keepDirtyOnReinitialize
destroyOnUnregister
subscription={defaultSubscription}
{...props}
render={({ submitting, ...formProps }) => (
<TabbedFormView
Expand All @@ -64,6 +65,13 @@ const TabbedForm = ({ initialValues, ...props }) => {
);
};

const defaultSubscription = {
submitting: true,
pristine: true,
valid: true,
invalid: true,
};

export default withRouter(TabbedForm);

export const TabbedFormView = ({
Expand Down