Skip to content

Higher-order components

Latest

Choose a tag to compare

@acdlite acdlite released this 26 Aug 20:55
· 1 commit to master since this release

Previously, if the render param of createRxComponent() was omitted, the resulting component would use the child-as-function pattern:

<RxComponent>
  {props => <ChildComponent {...props} />}
</RxComponent>

This version removes that feature. In its place, the second parameter of createRxComponent() can be either a render function or a React component class.

// Same as above example
const RxComponent = createRxComponent(mapProps, ChildComponent);

Additionally, createRxComponent() is now curried. This means you can remove the second parameter entirely, and instead of a normal React component, it will create a higher-order component:

const higherOrderComponent = createRxComponent(mapProps);

class MyComponent extends React.Component {...}

export default higherOrderComponent(MyComponent);

You can also use it as a decorator:

@createRxComponent(mapProps)
export default class MyComponent extends React.Component {...}