diff --git a/src/authenticated.js b/src/authenticated.js
index 6d1d618..31d1ea2 100644
--- a/src/authenticated.js
+++ b/src/authenticated.js
@@ -1,6 +1,6 @@
import React from 'react'
import { getLocalToken } from './local-token'
-import contextTypes from './context-types'
+import AuthContextType from './context-types'
export function hashed(o) {
return Object
@@ -31,6 +31,6 @@ export const authenticated = () => Component => {
}
}
}
- Authed.contextTypes = contextTypes
+ Authed.contextType = AuthContextType
return Authed
}
diff --git a/src/components/auth-context.js b/src/components/auth-context.js
index 5f2a8c6..4f395d9 100644
--- a/src/components/auth-context.js
+++ b/src/components/auth-context.js
@@ -1,5 +1,6 @@
import React from 'react'
-import contextTypes from '../context-types'
+import AuthContextType from '../context-types'
+import PropTypes from 'prop-types'
import { getHashValues } from '../lib/utils'
import TokenManager from './token-manager'
@@ -40,11 +41,6 @@ class Debug extends React.Component {
}
export class AuthContext extends React.Component {
- getChildContext() {
- const { provider, clientId, loggingInIndicator } = this.props
- return { provider, clientId, loggingInIndicator }
- }
-
isDebugEnabled = () => {
return !!(localStorage.getItem('debug') || '').match(/react-u5auth/)
}
@@ -59,18 +55,23 @@ export class AuthContext extends React.Component {
console.log('react-u5auth, debug', debug)
return (
-
{
- this.setState({ token })
- onTokenUpdate && onTokenUpdate(token)
- }}
- />
- { debug && }
- { showChildren && this.props.children }
+
+ {
+ this.setState({ token })
+ onTokenUpdate && onTokenUpdate(token)
+ }}
+ />
+ { debug && }
+ { showChildren && this.props.children }
+
)
}
}
-AuthContext.propTypes = contextTypes
-AuthContext.childContextTypes = contextTypes
+AuthContext.propTypes = {
+ provider: PropTypes.string.isRequired,
+ clientId: PropTypes.string.isRequired,
+ loggingInIndicator: PropTypes.element
+}
diff --git a/src/components/token-manager.js b/src/components/token-manager.js
index a8f67cc..566a329 100644
--- a/src/components/token-manager.js
+++ b/src/components/token-manager.js
@@ -1,6 +1,6 @@
import React from 'react'
import { setLocalToken, getLocalToken, getLocalExpiresAt } from '../local-token'
-import contextTypes from '../context-types'
+import AuthContextType from '../context-types'
import { hashed } from '../authenticated'
import { getHashValues } from '../lib/utils'
@@ -169,6 +169,6 @@ class TokenManager extends React.Component {
}
}
-TokenManager.contextTypes = contextTypes
+TokenManager.contextType = AuthContextType
export default TokenManager
diff --git a/src/context-types.js b/src/context-types.js
index a39dd9f..b3edf67 100644
--- a/src/context-types.js
+++ b/src/context-types.js
@@ -1,9 +1,5 @@
-import PropTypes from 'prop-types'
+import { createContext } from 'react'
-const contextTypes = {
- provider: PropTypes.string.isRequired,
- clientId: PropTypes.string.isRequired,
- loggingInIndicator: PropTypes.element
-}
+const AuthContextType = createContext()
-export default contextTypes
+export default AuthContextType