Skip to content

Instantly share code, notes, and snippets.

@emischorr
Last active February 24, 2019 12:17
Show Gist options
  • Save emischorr/2e3fd57fd8a3610dccf57273ff2e193f to your computer and use it in GitHub Desktop.
Save emischorr/2e3fd57fd8a3610dccf57273ff2e193f to your computer and use it in GitHub Desktop.
Middleware to tie Redux actions to the React user timing API
export default () => (next) => (action) => {
if (performance.mark === undefined) return next(action)
performance.mark(`${action.type}_start`)
const result = next(action)
performance.mark(`${action.type}_end`)
performance.measure(
`${action.type}`,
`${action.type}_start`,
`${action.type}_end`
)
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment