美文网首页
spread attributes {...this.props

spread attributes {...this.props

作者: hanxianshe_9530 | 来源:发表于2019-10-23 11:12 被阅读0次

if your now component props is

{
   booking: 4,
   isDisable: false
}

you can use this props in your child compoenet

<div {...this.props}> ... </div>

in you child component, you will receive all your parent props.
https://reactjs.org/docs/jsx-in-depth.html

https://zh-hans.reactjs.org/docs/jsx-in-depth.html

https://stackoverflow.com/questions/28452358/what-is-the-meaning-of-this-props-in-reactjs

const person = {
    name: "xgqfrms",
    age: 23,
    country: "China"
};

class TestDemo extends React.Component {
    render() {
        const {name, age, country} = {...this.props};
        // const {name, age, country} = this.props;
        return (
          <div>
              <h3> Person Information: </h3>
              <ul>
                <li>name={name}</li>
                <li>age={age}</li>
                <li>country={country}</li>
              </ul>
          </div>
        );
    }
}

ReactDOM.render(
    <TestDemo {...person}/>
    , mountNode
);

相关文章

网友评论

      本文标题:spread attributes {...this.props

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