Skip to content

A utility to connect functional component with the context

License

Notifications You must be signed in to change notification settings

uittorio/react-connect-ctx

Repository files navigation

react-connect-ctx

npm version Downloads

Connect React Context to your component easily and with type safety

Why

  • You dont want your Component to know about React.Context
  • You want to unit test your component without providing a context

Installation

npm i react-connect-ctx

Usage

import { connectContext } from 'react-connect-ctx';

export default connectContext(APP_CONTEXT)(
    PersonComponent,
    (context: AppContext): Partial<ComponentAProps> => {
        return {
           api: context.api
        }
});

##Click for full Example