方法一:ES6创建组件
export default class HolleCompany extends Component{
render() {
return (
<Text style={{fontSize:20,backgroundColor:'red'}}>Hello</Text>
);
}
}
方法二:ES5创建组建
var HolleCompany=React.createClass({
render() {
return <Text style={{fontSize:20,backgroundColor:'red'}}>Hello</Text>
}
});
module.exports=HolleCompany;
方法三:函数式,(无状态,不能使用this)
function HolleCompany() {
return <Text style={{fontSize:20,backgroundColor:'red'}}>Hello</Text>;
}
module.exports=HolleCompany;
本文介绍了三种使用React创建组件的方法:1. 使用ES6类组件;2. 使用ES5的React.createClass;3. 函数式组件(无状态)。每种方法都通过一个简单的“Hello”文本示例进行了展示。
1382

被折叠的 条评论
为什么被折叠?



