Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 7468247

Browse files
committed
Preventing infinite loops - only call update callback when form value actually changed
1 parent 922f37c commit 7468247

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

examples/quick-start/components/user-form.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Form, actions, Control, Field, Errors } from 'react-redux-form';
2+
import { LocalForm, Form, actions, Control, Field, Errors } from 'react-redux-form';
33
import { connect } from 'react-redux';
44

55
const required = (val) => !!(val && val.length);
@@ -37,6 +37,12 @@ class UserForm extends React.Component {
3737
render() {
3838
const { forms: { user }, dispatch } = this.props;
3939

40+
return (
41+
<LocalForm onSubmit={v=>console.log(v)}>
42+
<Control.text model=".username" />
43+
</LocalForm>
44+
)
45+
4046
return (
4147
<Form model="user" onSubmit={this.handleSubmit.bind(this)}>
4248
<div>

src/components/form-component.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ function createFormClass(s = defaultStrategy) {
8585
}
8686

8787
componentDidUpdate(prevProps) {
88-
this.handleUpdate();
8988
this.handleIntents();
9089

90+
if (!shallowEqual(prevProps.formValue, this.props.formValue)) {
91+
this.handleUpdate();
92+
}
93+
9194
if (!shallowEqual(prevProps.modelValue, this.props.modelValue)) {
9295
this.handleChange();
9396
}

0 commit comments

Comments
 (0)