I have a React component that displays styled text, and I want to have it load a network resource, listen for WebSocket input, and display notifications. In order to do this, I write Higher Order Component wrapper functions for each of these: withResource
, withSocket
, and withNotifications
.
When exporting the component, is this correct?
class TextComponent extends React.Component {
...
}
export default withResource(withSocket(withNotifications(TextComponent)))
You can use compose
from redux or recompose. For example:
import { compose } from 'redux'
export default compose(
withResource,
withSocket,
withNotifications
)(TextComponent)
import { compose } from 'recompose'
export default compose(
withResource,
withSocket,
withNotifications
)(TextComponent)