File tree Expand file tree Collapse file tree 3 files changed +14
-15
lines changed
Expand file tree Collapse file tree 3 files changed +14
-15
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
22import PropTypes from 'prop-types' ;
33import Api from './api' ;
4+ import { Context } from './context'
5+
46
57export default class Braintree extends React . Component {
68
@@ -21,13 +23,10 @@ export default class Braintree extends React.Component {
2123 tagName : 'div' ,
2224 }
2325
24- static childContextTypes = {
25- braintreeApi : PropTypes . instanceOf ( Api ) ,
26- }
27-
2826 constructor ( props ) {
2927 super ( props ) ;
3028 this . api = new Api ( props ) ;
29+ this . contextValue = { braintreeApi : this . api }
3130 }
3231
3332 componentDidMount ( ) {
@@ -49,18 +48,17 @@ export default class Braintree extends React.Component {
4948 return this . api . tokenize ( options ) ;
5049 }
5150
52- getChildContext ( ) {
53- return { braintreeApi : this . api } ;
54- }
55-
5651 render ( ) {
5752 const { className : providedClass , tagName : Tag } = this . props ;
5853 let className = 'braintree-hosted-fields-wrapper' ;
5954 if ( providedClass ) { className += ` ${ providedClass } ` ; }
55+
6056 return (
61- < Tag className = { className } >
62- { this . props . children }
63- </ Tag >
57+ < Context . Provider value = { this . contextValue } >
58+ < Tag className = { className } >
59+ { this . props . children }
60+ </ Tag >
61+ </ Context . Provider >
6462 ) ;
6563 }
6664
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+
3+ export const Context = React . createContext ( { braintreeApi : null } ) ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import PropTypes from 'prop-types' ;
3- import Api from './api' ;
3+ import { Context } from './context'
44
55export default class BraintreeHostedField extends React . Component {
66
@@ -20,9 +20,7 @@ export default class BraintreeHostedField extends React.Component {
2020 prefill : PropTypes . string ,
2121 }
2222
23- static contextTypes = {
24- braintreeApi : PropTypes . instanceOf ( Api ) ,
25- }
23+ static contextType = Context
2624
2725 state = { }
2826
You can’t perform that action at this time.
0 commit comments