2017-12-02 67 views
3

下面的代码示例是一个简化版本的一个组件。我不明白这个组件底部的代码,Case.wrappedComponent.propTypes部分。我无法在Internet上找到有关wrappedComponent的相关文档。在reactjs中,什么是wrappedComponent.propTypes?

问题

  1. 什么是它wrappedComponent和propTypes关键?
  2. 他们做什么?
  3. 我在哪里可以找到这些东西的文件?

    import React, { Component } from 'react'; 
    
    @inject('store') @observer 
    export default class Case extends Component { 
    
        constructor(props) { 
        super(props); 
    
        this.caseId = this.props.match.params.id; 
    
    
        this.setOtherComment = this.setOtherComment.bind(this) 
        this.submitOtherComment = this.submitOtherComment.bind(this) 
        } 
    
    
    
        render() { 
        return '...' 
        } 
    } 
    
    Case.wrappedComponent.propTypes = { 
        store: React.PropTypes.object.isRequired, 
        match: React.PropTypes.object.isRequired 
    }; 
    

回答

3

这是根据DOCS

与注射 进样组合使用propTypes和defaultProps等静态特性的的mobx-react(与注射)API和回绕到新的组件您传入的组件。这意味着,所得到的组件分配一个静态属性,将被应用到特定的,而不是原来的组件

........

如果你想上的数据断言正在被注入的 (无论是商店还是来自映射函数的数据),应该在包装组件上定义propTypes。其中 可通过静态属性wrappedComponent注入 组件

相关问题