@ohbug/redux-middleware

Redux middleware for propagating Redux state/actions to use with Ohbug

Usage no npm install needed!

<script type="module">
  import ohbugReduxMiddleware from 'https://cdn.skypack.dev/@ohbug/redux-middleware';
</script>

README

@ohbug/redux-middleware

npm npm bundle size Code style

English | 简体中文

Installation

yarn add @ohbug/browser @ohbug/redux-middleware

Usage

import Ohbug from '@ohbug/browser'
import { createStore, applyMiddleware } from 'redux'
import createOhbugMiddleware from '@ohbug/redux-middleware'
import reducer from './reducer'

Ohbug.init({ apiKey: 'YOUR_API_KEY' })

const store = createStore(reducer, applyMiddleware(createOhbugMiddleware()))

API

import type { Action, MiddlewareAPI } from 'redux'
type CreateOhbugMiddlewareOption = (
  action: Action,
  store: MiddlewareAPI
) => Action | false

example

import type { Action, MiddlewareAPI } from 'redux'
function before(action: Action, store: MiddlewareAPI) {
  if (action.type === 'foo') {
    // You can filter on certain sensitive information, which will not be collected
    // Just return false
    return false
  } else if (action.type === 'bar') {
    // If you want to collect some data after processing
    return {
      type: action.type,
      payload: store.getState() + action.payload,
    }
  }
  return action
}

// ...
const store = createStore(
  reducer,
  applyMiddleware(createOhbugMiddleware(before))
)