项目作者: GregRos

项目描述 :
A new way of attaching React lifecycle hooks.
高级语言: TypeScript
项目地址: git://github.com/GregRos/react-lifecycle-decorators.git
创建时间: 2016-10-15T15:02:59Z
项目社区:https://github.com/GregRos/react-lifecycle-decorators

开源协议:

下载


React Lifecycle Decorators

This library introduces a set of ES7/TypeScript decorators that offer you a new way to set up React lifecycle hooks.

Here is how it looks like:

  1. import {Life} from 'react-lifecycle-es7-decorators';
  2. class MyComponent extends React.Component {
  3. @Life.didUpdate
  4. @Life.didMount
  5. invalidate() {
  6. //code to execute on componentDidUpdate and componentDidMount
  7. }
  8. }
  9. class DerivedComponent extends MyComponent {
  10. @Life.didUpdate
  11. afterUpdate() {
  12. //code to execute on componentDidUpdate
  13. }
  14. }

The decorators add functions to the relevant lifecycle methods in a way that doesn’t interfere with previous hooks.

Also, when using an IDE with TypeScript tooling, the Life namespace reminds you of the available lifecycle hooks and their signatures.