https://github.com/disjukr/connect-react-context
like react-redux, connect react context to props. support typescript.
https://github.com/disjukr/connect-react-context
Last synced: about 1 month ago
JSON representation
like react-redux, connect react context to props. support typescript.
- Host: GitHub
- URL: https://github.com/disjukr/connect-react-context
- Owner: disjukr
- Created: 2018-07-01T10:31:49.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-08T14:59:27.000Z (almost 7 years ago)
- Last Synced: 2025-03-28T08:35:39.716Z (about 2 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/connect-react-context
- Size: 2.93 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# connect-react-context
like react-redux, connect react context to props. support typescript.## usage
```tsx
import * as React from 'react';
import { connectContext } from 'connect-react-context';
import { joinContext, ContextValues } from 'join-react-context';const helloContext = React.createContext('hello');
const worldContext = React.createContext('world');
type Contexts = [ typeof helloContext, typeof worldContext ];
const { Provider, Consumer } = joinContext([ helloContext, worldContext ]);const App = () => (
);interface ComponentProps {
a: string;
b: string;
c: string;
}
const Component: React.SFC = ({ a, b, c }) => (
{ a }, { b }{ c }
);
const ConnectedComponent = connectContext, ComponentProps, 'a' | 'b'>(
Consumer,
([ hello, world ], props) => ({ a: hello, b: world, ...props }),
)(Component);
```