ReactJS(5)Composition vs Inheritance

本文通过示例展示了ReactJS中组件的组合与继承两种设计模式的应用,并提供了客户端检查结账项目的实战案例链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ReactJS(5)Composition vs Inheritance

Composition VS Inheritance
function FancyBorder(props){
return (
<div className={‘FancyBorder FacyBorder-‘ + props.color}> {props.children} </div>
);
}
function WelcomeDialog(){
return (
<FancyBorder color=“blue”>
<h1 className=“Dialog-title”> Welcome </h1>
<p className=“Dialog-message”> Thank you for visiting our spacecraft! </p>
</FancyBorder>
);
}

Anything inside the <FancyBorder> JSX tag gets passed into the FancyBorder component as a children prop.

Thinking in React
https://facebook.github.io/react/docs/thinking-in-react.html

Client Side
Checkout example project
https://github.com/jackhutu/jackblog-react

Start the project
>npm install
my npm version is 5.0.2

Start to debug
>npm start dev

Some small changes in the file
>git diff src/components/Toaster/index.js
- const { msg } = nextProps
- const { hideMsg } = this.props
+ const msg = nextProps
+ const hideMsg = this.props


Server Side
https://github.com/jackhutu/jackblog-api-express
>npm install

Start develop
>gulp serve

Exceptions:
events.js:182
throw er; // Unhandled 'error' event
^
Error: The module '/Users/carl/work/jackblog/jackblog-api-express/node_modules/ccap/build/Release/hcaptha.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 48. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

Solution:
>sudo npm install -g gulp

Start Mongo and Redis
>bin/redis-server
>bin/mongod -f conf/mongodb.conf

Start the Server Side
>gulp serve

Read the Detail as well
https://github.com/jackhutu/jackblog-api-express.git

References:
https://facebook.github.io/react/docs/composition-vs-inheritance.html
https://facebook.github.io/react/docs/thinking-in-react.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值