Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 886 Bytes

README.md

File metadata and controls

31 lines (23 loc) · 886 Bytes

react-compose-contexts build

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>