Skip to content

Commit

Permalink
Use constructor instead of componentWillMount to register Field, Fiel…
Browse files Browse the repository at this point in the history
…ds, FieldArray. PR comment: #3956 (comment)
  • Loading branch information
asaarnak committed May 2, 2018
1 parent 9bf998f commit 82781c0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
11 changes: 4 additions & 7 deletions src/createField.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ const createField = (structure: Structure<*, *>) => {
'Field must be inside a component decorated with reduxForm()'
)
}
}

shouldComponentUpdate(nextProps: Props, nextState?: Object) {
return shallowCompare(this, nextProps, nextState)
}

componentDidMount() {
this.context._reduxForm.register(
this.name,
'Field',
Expand All @@ -46,6 +39,10 @@ const createField = (structure: Structure<*, *>) => {
)
}

shouldComponentUpdate(nextProps: Props, nextState?: Object) {
return shallowCompare(this, nextProps, nextState)
}

componentWillReceiveProps(nextProps: Props, nextContext: any) {
const oldName = prefixName(this.context, this.props.name)
const newName = prefixName(nextContext, nextProps.name)
Expand Down
3 changes: 0 additions & 3 deletions src/createFieldArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ const createFieldArray = (structure: Structure<*, *>) => {
'FieldArray must be inside a component decorated with reduxForm()'
)
}
}

componentDidMount() {
this.context._reduxForm.register(
this.name,
'FieldArray',
Expand Down
8 changes: 2 additions & 6 deletions src/createFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,14 @@ const createFields = (structure: Structure<*, *>) => {
if (error) {
throw error
}
const { _reduxForm: { register } } = context
this.names.forEach(name => register(name, 'Field'))
}

shouldComponentUpdate(nextProps: Props) {
return shallowCompare(this, nextProps)
}

componentDidMount() {
const { context } = this
const { _reduxForm: { register } } = context
this.names.forEach(name => register(name, 'Field'))
}

componentWillReceiveProps(nextProps: Props) {
if (!plain.deepEqual(this.props.names, nextProps.names)) {
const { context } = this
Expand Down

0 comments on commit 82781c0

Please sign in to comment.