从函数访问组件的道具

时间:2019-08-02 09:40:03

标签: javascript reactjs components mobx

我正在学习与mobx进行状态管理的反应,最近遇到了一个场景,在该场景中,我可能不得不处理可能会更新react组件的props的函数。 该功能不是所述组件的一部分,并且该功能通过bootstrap js条目公开,以允许任何外部模块访问该组件并启动组件的重新呈现。 由于无法使用js,我目前无法执行此操作,请建议在react中这样做是否可行,谢谢帮助。

我尝试了一些选择,但无济于事,我无法访问此组件的道具

PropTypes.instanceOf(SampleComponent).isRequired 

以下是我的示例组件

@observer
class SampleComponent extends React.Component {
    constructor(props) {
    .......
    }

    state = {
        ........
    };

    componentDidMount() {
        ..........
    }

    componentDidCatch(err) {
        ..........
    }

    componentWillUnmount() {
        .........
    }


    render() {
    .............
    }

SampleComponent.propTypes = {
    sampleProp: PropTypes.bool,
};

SampleComponent.defaultProps = {
    sampleProp: false,
};

function updateSampleProp(value) {
    ?????
}

export default injectIntl(SampleComponent);
export { updateSampleProp }

0 个答案:

没有答案