反模式是否在componentWillReceiveProps中返回undefined或null?

时间:2016-03-23 14:14:12

标签: reactjs

  1. 在componentWillReceiveProps?
  2. 中是否返回了未定义的反模式

    示例:

    class MyComponent extends React.Component {
      componentWillReceiveProps(nextProps) {
        if (nextProps.somethingHappened) {
           return
        }
        otherThingHappened()
      }
    }

    1. 反模式是否在componentWillReceiveProps中返回null?
    2. 示例:

      class MyComponent extends React.Component {
        componentWillReceiveProps(nextProps) {
          if (nextProps.somethingHappened) {
             return null
          }
          otherThingHappened()
        }
      }

1 个答案:

答案 0 :(得分:4)

不是。根据{{​​3}} componentWillReceiveProps预计不会返回任何内容。虽然返回一个将在之后被丢弃的值,但这似乎很奇怪。

相关问题