Wednesday, July 13, 2022

ตัวอย่างการใช้ spread attributes

ตัวอย่างที่ 1

var parts = ['two', 'three'];
var numbers = ['one', ...parts, 'four', 'five'];
จะได้ว่า numbers เก็บค่าเป็น ["one", "two", "three", "four", "five"]


ตัวอย่างที่ 2

var person= {
    name: 'Alex',
    age: 35 
}

เมื่อสร้าง component ยกตัวอย่างเช่น 
<Modal {...person} title='Modal heading' animation={false} />

จะมีความหมายเดียวกันกับ
<Modal name={person.name} age={person.age} title='Modal heading' animation={false} />

No comments:

Post a Comment