https://github.com/morulus/connect-context
Connect/provide context to/from the stateless component
https://github.com/morulus/connect-context
Last synced: about 1 year ago
JSON representation
Connect/provide context to/from the stateless component
- Host: GitHub
- URL: https://github.com/morulus/connect-context
- Owner: morulus
- License: mit
- Created: 2017-05-10T02:23:37.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-09-06T14:43:55.000Z (almost 8 years ago)
- Last Synced: 2025-05-18T04:16:26.557Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 70.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
connect-context
==
Connect/provide context to/from the stateless component
```js
import { createProvider, connectContext } from 'connect-context';
const Provider = createProvider({
Layout: ({ children }) => (
{children}
),
});
const contextTypes = {
Layout: PropTypes.func.isRequired,
};
connectContext(contextTypes)
(({ Layout }) => (
Hello, React!
));
//
Hello, React
```
Docs
----
### provideContext(contextProps, [contextTypes]) : connector
Prepare context connector, which can be applied on an existing component.
_Params_:
- `contextProps` {object|function} Context object or getChildContext function;
- If is a function, accepts `props`, `state` parameters.
- `contextTypes` {object} Context types (in case of contextProps is a function)
_Returns_: {function} connector
### createProvider(contextProps, [contextTypes]) : Component
Create React component, which provides specified context.
_Params_:
- `contextProps` {object|function} Context itselfs or getChildContext function;
- If is a function, accepts `props`, `state` parameters.
- `contextTypes` {object} Context types (in case of contextProps is a function)
_Returns_: {function} Component
### connectContext(contextTypes, mapContextToProps): connector
Connect context (specified in contextTypes) to the component.
_Params_:
- `contextTypes` {object} Context types
- `mapContextToProps(context, props)` {function} Map context to the props (by the defaults maps the entire context to the props)
_Returns_: {function} connector
### connect(contextTypes, mapAllToProps): connector
Decorator for [react-redux](https://github.com/reactjs/react-redux) _connect_, which provides you with a possibility to map context to props and state to props in the same function.
_Params_:
- `contextTypes` {object} Context types
- `mapAllToProps(context, state, props)` {function} Map context, state, and own props
_Returns_: {function} connector
__*__ Function `connect` requires `react-redux` as optional dependence. It means that if your build envelopment has no react-redux, connect function will be unreachable.
Author
----
Vladimir Kalmykov
License
----
MIT, 2017