美文网首页
{...this.props}的用法

{...this.props}的用法

作者: hanxianshe_9530 | 来源:发表于2019-11-05 15:20 被阅读0次

除了WrappedComponent自己的属性,WrappedComponent又增加了三个属性

import React from 'react';
import bindAll from 'lodash.bindall';

/* Higher Order Component to get and set the project title
 * @param {React.Component} WrappedComponent component to receive project title related props
 * @returns {React.Component} component with project loading behavior
 */
const TitledHOC = function (WrappedComponent) {
    class TitledComponent extends React.Component {
        constructor (props) {
            super(props);
            bindAll(this, [
                'handleUpdateProjectTitle'
            ]);
            this.state = {
                projectTitle: null
            };
        }
        handleUpdateProjectTitle (newTitle) {
            this.setState({projectTitle: newTitle});
        }
        render () {
            return (
                <WrappedComponent
                    canEditTitle
                    projectTitle={this.state.projectTitle}
                    onUpdateProjectTitle={this.handleUpdateProjectTitle}
                    {...this.props}
                />
            );
        }
    }

    return TitledComponent;
};

export {
    TitledHOC as default
};

相关文章

  • {...this.props}的用法

    除了WrappedComponent自己的属性,WrappedComponent又增加了三个属性

  • this.props 的神奇用法(路由传参)

    问题描述: 移动端培训项目,之前大多用GET请求。最近接到一个功能需求,后台给我做了五个POST接口,一瞬间有...

  • 2-组件和生命周期

    组件的用法与原生的 HTML 标签完全一致,可以任意加入属性,组件的属性可以在组件类的this.props对象上获...

  • this.props.XXX与this.props.childr

    项目中遇到,瞬间懵逼,这不是我认识的this.props用法啊!一问才知道,原来还有这种操作,特此留存,以备后查!...

  • React入门 —— this.props

    React入门 —— this.props this.props React允许将代码封装成组件,然后像插入普通 ...

  • React Native 之{...this.props}解惑

    一、 {...this.props}之惑 接触rn也有段时间了,有{...this.props}这么个东东老是出现...

  • this.props

    链接地址:http://lib.csdn.net/article/react/20355 这篇文章介绍的比较基础,...

  • {...this.props}

    {...this.props}是props所提供的语法糖,可以将父组件的所有属性复制给子组件

  • react传值

    一、父传子 子组件如何接收 (this.props)

  • React-Native 组件的属性

    1. props this.props contains the props that were defined ...

网友评论

      本文标题:{...this.props}的用法

      本文链接:https://www.haomeiwen.com/subject/wazsbctx.html