javascript React:使用spread(... spread)运算符

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript React:使用spread(... spread)运算符相关的知识,希望对你有一定的参考价值。

hygiene: {
            toiletries: {
                question:
                    'Do you need help buying toiletries like soap and shampoo?',
                agree: false
            },
            washing: {
                question: 'Do you need help washing your hair and body?',
                agree: false
            },
            laundry: {
                question:
                    'Do you need help doing your laundry and cleaning your clothes?',
                agree: false
            },
            more: ''
        },
        toilet: {
            access: {
                question: 'Do you need help to access the toilet?',
                agree: false
            },
            toiletUse: {
                question: 'Do you need help to use the toilet?',
                agree: false
            },
            nightAccess: {
                question: 'Do you need help to go to the toilet at night',
                agree: false
            },
            more: ''
        },
//Use spread to open up the object in state to setState
handleChangeInput = (event, qs, section) => {
        const target = event.target;
        // console.log("target", target)
        const value = target.name === 'more' ? target.value : null;
        console.log("value", value)
        this.setState({
            [section]: {
                ...this.state[section],
                [qs]: { ...this.state[section][qs], more: value }
            }
        });
    };
# Routing pages
// Use section to name the index of the object in state (above)

<Route
      path="/toilet"
      render={props => (
          <Toilet
              info={this.state.toilet}
              section="toilet"
              handleChangeInput={this.handleChangeInput}
              toggleChange={this.toggleChange}
          />
      )}
  />

以上是关于javascript React:使用spread(... spread)运算符的主要内容,如果未能解决你的问题,请参考以下文章

javascript 使用Object spread向对象添加新属性

javascript 使用spread运算符复制对象或数组

javascript 使用Spread运算符来就地评估阵列

javascript JavaScript Spread运算符

[Javascript] Conditionally spread entries to a JavaScript object

如何使用 JavaScript spread... 语法更改对象的一个​​字段,该字段属于数组并通过名称-值对访问?