-
Notifications
You must be signed in to change notification settings - Fork 0
useContext
Александр edited this page Jan 17, 2023
·
2 revisions
export function useContext<T>(context: React.Context<T>): { val: T }
Accepts a context object.
Subscribes to context changes and returns { val: <context_value> }
.
import { afc, useContext } from 'react-afc'
import { NameContext } from './NameContext'
function Component(props) {
const context = useContext(NameContext)
function greet() {
const name = context.val
return `Hi, ${name}!`
}
return () => (
<p>{greet()}</p>
)
}
export default afc(Component)
Component
Lifecycle
State
Redux
Other