An open API service indexing awesome lists of open source software.

https://github.com/disjukr/join-react-context

join multiple react context into one. support typescript.
https://github.com/disjukr/join-react-context

Last synced: 2 months ago
JSON representation

join multiple react context into one. support typescript.

Awesome Lists containing this project

README

        

# join-react-context
join multiple react context into one.

works perfectly with typescript.

## usage
```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 }
}

);
}
```