react-compose-contexts
v1.0.0
Published
Compose context providers to increase readability.
Downloads
8
Readme
react-compose-contexts
Compose context providers to increase readability.
npm install --save-prod react-compose-contexts
Usage
import {createContext, FC} from 'react';
import {renderToString} from 'react-dom';
import {composeContexts} from 'react-compose-contexts';
const Context1 = createContext('A');
const Context2 = createContext(123);
const ConsumerComponent: FC = () => {
const value1 = useContext(Context1);
const value2 = useContext(Context2);
return <span>{value1}{value2}</span>;
};
renderToString(composeContexts([
[Context1, 'B'],
[Context2, 456],
], createElement(ConsumerComponent)));
// → <span>B456</span>