React Observatory
  • Introduction
  • Motivation
  • Dynamic Injection
    • Reducers
    • Epics
  • API Reference
    • applyAsyncEpics
    • applyAsyncReducers
    • composeReducerCreator
    • createRootEpic
    • injectEpic
    • injectReducer
    • withAction
    • withRouterAction
Powered by GitBook
On this page
  • Arguments
  • Returns
  • Example: Injecting an Epic in the Container Component
  • containers/Blog/index.js
  • Example: Injecting the Epic with Redux compose into connected Component
  1. API Reference

injectEpic

PreviouscreateRootEpicNextinjectReducer

Last updated 6 years ago

injectEpic() is used to create a that will inject the epic into the runtime.

The Epic stays in the runtime after component is unmounted.

Arguments

  1. epic (): an epic to inject.

Returns

(Function): function

Example: Injecting an Epic in the

containers/Blog/index.js

import { injectEpic } from '@react-observatory/inject-epic'
import epic from './epics'
import Blog from './Blog'

const withEpic = injectEpic(epic)

export default withEpic(Blog)
import { compose } from 'redux'
import { connect } from 'react-redux'
import { injectEpic } from '@react-observatory/inject-epic'
import Blog from './Blog'
import epic from './epics'

function mapStateToProps(state) {
  return {
    blog: state.blog,
  }
}

const mapDispatchToProps = { submitComment: () => ({ type: 'SubmitComment' }) }

const withConnect = connect(mapStateToProps, mapDispatchToProps)

const withEpic = injectEpic(epic)

export default compose(
  withEpic,
  withConnect
)(Blog)

Example: Injecting the Epic with Redux into Component

Higher-Order Components
Epic
Higher-Order Components
Container Component
compose
connected