withRouterAction

Higher-Order Components for dispatching an action with the data from the router context, when the route is matched and corresponding component is about to mount.

The action will receive the location and the match from react-router.

withRouterAction(action) is useful, when you want to run side-effects in the Epics right after Component being loaded.

Arguments

  1. action (string): Redux Action to dispatch.

Returns

(Function): A Higher-Order Components function that enables us to dispatch an Action, when Component is mounted.

Example: Dispatching an Action, when the Container is mounted.

./src/containers/About

import { withRouterAction } from '@react-observatory/with-router-action'
import About from './About'

// It's nice to prefix the Actions, so it's easy to recognize them in the DevTool.
export default withRouterAction('RouterAction.About')(About)

Last updated