mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
* fix: converted single to triple backticks13 * fix: added prefix Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com> * fix: removed language in wrong place Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com> * fix: add language postfix Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com> * fix: removed language in wrong place Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>
75 lines
1.7 KiB
Markdown
75 lines
1.7 KiB
Markdown
---
|
|
title: React - Components
|
|
localeTitle: رد الفعل - مكونات
|
|
---
|
|
## رد الفعل - مكونات
|
|
|
|
مكونات قابلة لإعادة الاستخدام في react.js. يمكنك ضخ القيمة في الدعائم كما هو موضح أدناه:
|
|
|
|
```jsx
|
|
function Welcome(props) {
|
|
return <h1>Hello, {props.name}</h1>;
|
|
}
|
|
|
|
const element = <Welcome name="Faisal Arkan" />;
|
|
ReactDOM.render(
|
|
element,
|
|
document.getElementById('root')
|
|
);
|
|
```
|
|
|
|
`name="Faisal Arkan"` سيعطي قيمة في `{props.name}` من `function Welcome(props)` `{props.name}` المكونة التي أعطيت القيمة `name="Faisal Arkan"` ، بعد أن تتفاعل ستجعل العنصر في html.
|
|
|
|
### طرق أخرى لإعلان المكونات
|
|
|
|
هناك العديد من الطرق لاعلان المكونات عند استخدام React.js، ولكن هناك نوعان من المكونات، ومكونات **_عديمي الجنسية_** ومكونات **_جليل._**
|
|
|
|
### جليل
|
|
|
|
#### مكونات نوع الطبقة
|
|
|
|
```jsx
|
|
class Cat extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
this.state = {
|
|
humor: 'happy'
|
|
}
|
|
}
|
|
render() {
|
|
return(
|
|
<div>
|
|
<h1>{this.props.name}</h1>
|
|
<p>
|
|
{this.props.color}
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
```
|
|
|
|
### مكونات عديمة الحالة
|
|
|
|
#### مكونات وظيفية (وظيفة السهم من ES6)
|
|
|
|
`const Cat = props => {
|
|
return (
|
|
<div>
|
|
<h1>{props.name}</h1>
|
|
<p>{props.color}</p>
|
|
</div>;
|
|
);
|
|
};
|
|
`
|
|
|
|
#### مكونات العودة الضمنية
|
|
|
|
```jsx
|
|
const Cat = props =>
|
|
<div>
|
|
<h1>{props.name}</h1>
|
|
<p>{props.color}</p>
|
|
</div>;
|
|
``` |