- 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.
- 基于粒計(jì)算模型的圖像處理
- Learning C# by Developing Games with Unity 2020
- C# 從入門到項(xiàng)目實(shí)踐(超值版)
- Mastering Swift 2
- Hands-On Microservices with Kotlin
- Microsoft System Center Orchestrator 2012 R2 Essentials
- 大學(xué)計(jì)算機(jī)基礎(chǔ)(第2版)(微課版)
- Oracle 18c 必須掌握的新特性:管理與實(shí)戰(zhàn)
- Raspberry Pi Home Automation with Arduino(Second Edition)
- Mastering React
- Go語言編程
- Principles of Strategic Data Science
- 零基礎(chǔ)學(xué)C語言(升級(jí)版)
- Puppet 5 Beginner's Guide(Third Edition)
- Python數(shù)據(jù)預(yù)處理技術(shù)與實(shí)踐