join react context
npm install join-react-contextworks perfectly with typescript.
tsx
import * as React from 'react';
import {
Providers,
joinContext,
joinProvider,
joinConsumer,
} from 'join-react-context';const contextA = React.createContext('context a');
const contextB = React.createContext('context b');
{ // providers array style
,
,
]}>
{children}
// is same as...
{children}
}
{ // providers fragment style
>}>
{children}
}
{ // join tuple style
type Contexts = [ typeof contextA, typeof contextB ];
const { Provider, Consumer } = joinContext([ contextA, contextB ]);
const App = () => (
);
const Component = () => (
{ ([ a, b ]) => { a }, { b } }
);
}
{ // join object style
const { Provider, Consumer } = joinContext({ a: contextA, b: contextB });
const App = () => (
);
const Component = () => (
{ ({ a, b }) => { a }, { b } }
);
}
{ // join mixed style (vice versa)
type Contexts = [ typeof contextA, typeof contextB ];
const Provider = joinProvider([ contextA, contextB ]);
const Consumer = joinConsumer({ a: contextA, b: contextB });
const App = () => (
);
const Component = () => (
{ ({ a, b }) => { a }, { b } }
);
}
``