- Build Applications with Meteor
- Dobrin Ganev
- 218字
- 2021-07-09 19:48:54
Inheritance versus composition
Facebook and the React community encourage the use of composition over classical inheritance. It can be said that any other pattern to reuse code is considered anti-pattern in React. A lot more can be said about that, but React has been heavily used in production at Facebook without using inheritance for sure. In such a large-scale application, the advantage of building independent pieces and combining them to form a complex functionally is what made React so popular. Components can be moved around, organized by common functionality; they can be well tested and refactored without much of a risk of breaking other parts of the system.
Extending from the React.Component:
class Greeting extends
React.Component {
constructor(props){ // ES6 class constructor
super(props) // ES6
}
render() {
return <h1>Hello, {this.props.name}</h1>; //local
}
}
Instead of creating a new Greeting instance, we are adding it as a <Greeting/> tag:
ReactDOM.render(
<Greeting name="Johny"/>,document.getElementById('root'))
Some components can be strictly presentational; others may not know who can be their children components in advance. Many namings later came from the community, Smart and Dumb components, Containers and Components, functional and classical.
How React is used it's all up to the developers, the team, and the organization. It's a very powerful and unopinionated library and can be used along with other frameworks.
- Getting Started with Citrix XenApp? 7.6
- What's New in TensorFlow 2.0
- Mastering Adobe Captivate 2017(Fourth Edition)
- Learning SQLite for iOS
- x86匯編語言:從實模式到保護模式(第2版)
- C/C++常用算法手冊(第3版)
- Reactive Android Programming
- FPGA Verilog開發(fā)實戰(zhàn)指南:基于Intel Cyclone IV(進階篇)
- C專家編程
- HTML5+CSS3+JavaScript 從入門到項目實踐(超值版)
- HTML5移動Web開發(fā)
- Java Web開發(fā)基礎(chǔ)與案例教程
- 從零開始構(gòu)建深度前饋神經(jīng)網(wǎng)絡(luò):Python+TensorFlow 2.x
- PHP動態(tài)網(wǎng)站開發(fā)實踐教程
- 微信小程序開發(fā)邊做邊學(xué)(微課視頻版)