2017-12-02 65 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注入 組件

相關問題