react native ES6语法规则记录

来源:互联网 发布:cnc编程招聘信息 编辑:程序博客网 时间:2024/06/05 07:02

1.函数定义:method1(){

}

2.组件类定义:

class classA extends React.Component {    render() {        return (        );    }}
3.组件属性
class Video extends React.Component {    static defaultProps = {        maxLoops: 10,    };  // 注意这里有分号    static propTypes = {        videoSrc: React.PropTypes.string.isRequired,    };  // 注意这里有分号    render() {        return (             );    } // 注意这里既没有分号也没有逗号}
4.组件state
class Video extends React.Component {    state = {        loopsRemaining: this.props.maxLoops,    }}
5.回调函数
class PostInfo extends React.Component{    handleOptionsButtonClick(e){        this.setState({showOptionsModal: true});    }    render(){        return (            <TouchableHighlight                        onPress={e=>this.handleOptionsButtonClick(e)}                >                <Text>{this.props.label}</Text>            </TouchableHighlight>        )    },}


0 0
原创粉丝点击