switchayakul / react-context-hoc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-context-hoc

import withContext from './withContext'
import AContext from './contexts/A'
import BContext from './contexts/B'

// Provides AContext.
@withContext({
    provide: [AContext],
})

// Comsumes AContext.
@withContext({
    consume: {
        aContext: AContext,
    },
})

// Provides AContext, and comsumes AContext and BContext.
@withContext({
    provide: [AContext],
    consume: {
        aContext: AContext,
        bContext: BContext,
    },
})

// You can access the consumed contexts from your class's props.
export default class extends PureComponent {
    ...
    render() {
        const { aContext, bContext } = this.props
        ...
    }
    ...
}

About


Languages

Language:JavaScript 100.0%