数组扩展,在 react native 里写样式表可以用这个来简单实现 mixin

const mixin = {
    btn: {
        width: 200,
        height: 50,
        padding: 10,
    },
}

export default stylesheet {
    btnPrimary: {
        ...mixin.btn,
        backgroundColor: 'blue',
    },
}

数组克隆

const orig = ['a', 'b', 'c'];
const clone = [...orig];

字符串拆分

[...'foo']
// ['f', 'o', 'o']

用变量值当键名动态 setState

export default class DemoScreen extends React.Component {
    state = {
        name: '',
        age: 0,
    }

    renderTextInput = (field, value) => {
        return (
            <TextInput style={styles.formInput}
                onChangeText={ text => this.setState( {[field]: text} ) }
                value={ this.state[field] }
            />
        )
    }

    render() {
        return (
            { this.renderTextInput('name', 'John') }
            { this.renderTextInput('age', '21') }
        )
    }
}