@@ -2,6 +2,12 @@ import React from 'react'
22import PropTypes from 'prop-types'
33import isEqual from 'lodash.isequal'
44
5+ // Create a new context
6+ export const FormContext = React . createContext ( {
7+ registerComponent : ( ) => { } ,
8+ unregisterComponent : ( ) => { } ,
9+ } )
10+
511class Form extends React . Component {
612 static propTypes = {
713 /** Form html chilren */
@@ -16,10 +22,6 @@ class Form extends React.Component {
1622 serverErrors : PropTypes . shape ( { } ) ,
1723 }
1824
19- static childContextTypes = {
20- ICFormable : PropTypes . object ,
21- }
22-
2325 constructor ( ) {
2426 super ( )
2527 this . state = { serverErrors : null }
@@ -28,15 +30,6 @@ class Form extends React.Component {
2830 this . invalidComponents = [ ]
2931 }
3032
31- getChildContext ( ) {
32- return {
33- ICFormable : {
34- registerComponent : this . registerComponent ,
35- unregisterComponent : this . unregisterComponent ,
36- } ,
37- }
38- }
39-
4033 componentDidMount ( ) {
4134 this . updateModel ( )
4235 }
@@ -100,11 +93,17 @@ class Form extends React.Component {
10093
10194 render ( ) {
10295 const { children, formProps } = this . props
96+ const contextValue = {
97+ registerComponent : this . registerComponent ,
98+ unregisterComponent : this . unregisterComponent ,
99+ }
103100
104101 return (
105- < form { ...formProps } onSubmit = { this . handleSubmit } >
106- { children }
107- </ form >
102+ < FormContext . Provider value = { contextValue } >
103+ < form { ...formProps } onSubmit = { this . handleSubmit } >
104+ { children }
105+ </ form >
106+ </ FormContext . Provider >
108107 )
109108 }
110109}
0 commit comments