gpt4 book ai didi

reactjs - 在reactjs中,wrappedComponent.propTypes是什么?

转载 作者:行者123 更新时间:2023-12-03 14:13:29 25 4
gpt4 key购买 nike

下面的代码示例是组件的简化版本。我不明白该组件底部的代码,即 Case.wrappedComponent.propTypes 部分。我在互联网上也找不到有关wrappedComponent的相关文档。

问题:

  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
    };

最佳答案

这是 mobx-react 的 API(带注入(inject)),根据 DOCS

Using propTypes and defaultProps and other static properties in combination with inject Inject wraps a new component around the component you pass into it. This means that assigning a static property to the resulting component, will be applied to the HoC, and not to the original component

........

if you want to make assertions on the data that is being injected (either stores or data resulting from a mapper function), the propTypes should be defined on the wrapped component. Which is available through the static property wrappedComponent on the inject component

关于reactjs - 在reactjs中,wrappedComponent.propTypes是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47611926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com