react-performance icon indicating copy to clipboard operation
react-performance copied to clipboard

Create a @measure decorator

Open twheys opened this issue 7 years ago • 0 comments

Would love to see the measure function as a decorator:

class MyComponent extends React.Component {/* ... */}

export default ReactPerformance.measure({
  getId: 'some_recognizable_identifier',
  Component: MyComponent,
  isCollapsed: false,
})

Would look good as

import {measure} from 'react-performance'

@measure({
  getId: 'some_recognizable_identifier',
  isCollapsed: false,
})
export default class MyComponent extends Component {/* ... */}

And with redux...

@measure({getId: 'some_recognizable_identifier'})
@connect(mapStateToProps, mapDispatchToProps)
class MyComponent extends React.Component {/* ... */}

This syntax would make react-performance easier to play around with because it would involve less changes to the code, ie you would only need to decorate components which would make it easier to add and remove profiling.

twheys avatar Jan 11 '19 09:01 twheys