@ohbug/redux-middleware
v1.0.13
Published
Redux middleware for propagating Redux state/actions to use with Ohbug
Downloads
9
Readme
@ohbug/redux-middleware
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))
)