connect
Note: If you're working with React > 16.3, we highly recommend using the useFela hook instead.
It's more easy and safe to use and also has the best rendering performance.
A HoC (Higher-order Component(new tab)) that provides the ability to map rendered classes to the component's props using the 
stylesArguments
| Argument | Type | Description | 
|---|---|---|
| rules | Object or Function | An object containing named rules or a function that produces such an object based on the props of a component. | 
| config | Object? | An object containing settings to configure Wrapper Component. | 
Configuration parameters
| Parameter | Type | Default | Description | 
|---|---|---|---|
| pure | boolean |  | A parameter that enables / disables the behavior when the output component is pure. | 
Returns
(Function): Component connector that passes the
stylesrulesthemeProvided properties
| Property | Type | Description | 
|---|---|---|
| styles | Object | An object containing class names by keys. | 
| rules | Object | An object containing style rules by keys (used for extend inner components). | 
| theme | Object | An object containing the style theme, if provided. | 
Imports
import { connect } from 'react-fela'import { connect } from 'preact-fela'import { connect } from 'inferno-fela'Example
Header.js
const Header = ({ title, styles }) => (  <header className={styles.container}>    <h1 className={styles.text}>{title}</h1>  </header>)const container = (props) => ({  textAlign: 'center',  padding: '20px',  height: '200px',})const text = (props) => ({  lineHeight: 1.2,  fontSize: props.size,  color: props.color,})const ConnectedHeader = connect({  container,  text,})(Header)// Usageconst Usage = <ConnectedHeader title="Hello World" color="red" size="17px" />Using a Function of Props
Header.js
const Header = ({ title, styles }) => (  <header className={styles.container}>    <h1 className={styles.text}>{title}</h1>  </header>)const rules = ({ size, color }) => ({  container: {    textAlign: 'center',    padding: '20px',    height: '200px',  },  text: {    lineHeight: 1.2,    fontSize: size,    color: color,  },})const ConnectedHeader = connect(rules)(Header)// Usageconst Usage = <ConnectedHeader title="Hello World" color="red" size="17px" />Disabling Pure Component Behavior
const ConnectedHeader = connect(rules, { pure: false })(Header)Extending Styles
To extend the styles that are injected through the
connectExtend Property
It's possible to extend component styles with an
extendHeader.js
const Header = ({ title, styles }) => (  <header className={styles.container}>    <h1 className={styles.text}>{title}</h1>  </header>)const rules = ({ size, color }) => ({  container: {    textAlign: 'center',    padding: '20px',    height: '200px',  },  text: {    lineHeight: 1.2,    fontSize: size,    color: color,  },})const ConnectedHeader = connect(rules)(Component)const extend = ({ bgColor }) => ({  container: {    backgroundColor: bgColor,    padding: '30px',  },  text: {    fontWeight: 700,  },})// Usageconst Usage = (  <ConnectedHeader    title="Hello World"    size="17px"    color="red"    bgColor="blue"    extend={extend}  />)Reconnection Pattern
Instead of directly passing an
extendHeader.js
const Header = ({ title, styles }) => (  <header className={styles.container}>    <h1 className={styles.text}>{title}</h1>  </header>)const rules = ({ size, color }) => ({  container: {    textAlign: 'center',    padding: '20px',    height: '200px',  },  text: {    lineHeight: 1.2,    fontSize: size,    color: color,  },})const ConnectedHeader = connect(rules)(Component)const extend = ({ bgColor }) => ({  container: {    backgroundColor: bgColor,    padding: '30px',  },  text: {    fontWeight: 700,  },})const ExtendedHeader = connect(extend)(ConnectedHeader)// Usageconst Usage = (  <ExtendedHeader title="Hello World" size="17px" color="red" bgColor="blue" />)Proxying and Rules Property
If you want to proxy the rules for child components, you can use the
rulesHeader.js
const Header = ({ title, styles }) => (  <header className={styles.container}>    <h1 className={styles.text}>{title}</h1>  </header>)const rules = ({ size, color }) => ({  container: {    textAlign: 'center',    padding: '20px',    height: '200px',  },  text: {    lineHeight: 1.2,    fontSize: size,    color: color,  },})const ConnectedHeader = connect(rules)(Header)const extend = ({ bgColor }) => ({  container: {    backgroundColor: bgColor,    padding: '30px',  },  text: {    fontWeight: 700,  },})const HeaderProxy = ({ rules }) => (  <ConnectedHeader size="17px" extend={rules} />)const ExtendedHeader = connect(extend)(HeaderProxy)// Usageconst Usage = <ExtendedHeader title="Hello World" color="red" bgColor="blue" />The injected
rulesstyles