Skip to content

Commit 8b5a491

Browse files
merging all conflicts
2 parents 993bfa3 + 27d86ff commit 8b5a491

File tree

5 files changed

+197
-10
lines changed

5 files changed

+197
-10
lines changed

src/content/learn/add-react-to-an-existing-project.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ title: اضافه کردن ری‌اکت به یک پروژه موجود
2424
2. **`/some-app` را به‌عنوان *مسیر پایه*** در پیکربندی فریم‌ورک خود مشخص کنید (راهنما: [Next.js](https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath)، [Gatsby](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)).
2525
3. **سرور یا پروکسی خود را پیکربندی کنید** تا همه درخواست‌های زیر مسیر `/some-app/` توسط اپلیکیشن ری‌اکت شما مدیریت شوند.
2626

27+
<<<<<<< HEAD
2728
این کار تضمین می‌کند که بخش ری‌اکت اپلیکیشن شما می‌تواند از [بهترین شیوه‌های موجود](/learn/build-a-react-app-from-scratch#consider-using-a-framework) که در این فریم‌ورک‌ها تعبیه شده‌اند بهره‌مند شود.
29+
=======
30+
This ensures the React part of your app can [benefit from the best practices](/learn/build-a-react-app-from-scratch#consider-using-a-framework) baked into those frameworks.
31+
>>>>>>> 27d86ffe6ec82e3642c6490d2187bae2271020a4
2832
2933
بسیاری از فریم‌ورک‌های مبتنی بر ری‌اکت فول‌استک هستند و به اپلیکیشن ری‌اکت شما اجازه می‌دهند از قابلیت‌های سرور استفاده کند. با این حال، حتی اگر نتوانید یا نخواهید جاوااسکریپت را روی سرور اجرا کنید، می‌توانید از همان رویکرد استفاده کنید. در این حالت، خروجی HTML/CSS/JS را (خروجی [`next export`](https://nextjs.org/docs/advanced-features/static-html-export) در Next.js یا حالت پیش‌فرض در Gatsby) در مسیر `/some-app/` سرو کنید.
3034

src/content/reference/react-dom/components/index.md

Lines changed: 124 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,137 @@ Similar to the [DOM standard,](https://developer.mozilla.org/en-US/docs/Web/API/
162162

163163
### Custom HTML elements {/*custom-html-elements*/}
164164

165-
If you render a tag with a dash, like `<my-element>`, React will assume you want to render a [custom HTML element.](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) In React, rendering custom elements works differently from rendering built-in browser tags:
166-
167-
- All custom element props are serialized to strings and are always set using attributes.
168-
- Custom elements accept `class` rather than `className`, and `for` rather than `htmlFor`.
165+
If you render a tag with a dash, like `<my-element>`, React will assume you want to render a [custom HTML element.](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements)
169166

170167
If you render a built-in browser HTML element with an [`is`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/is) attribute, it will also be treated as a custom element.
171168

172-
<Note>
169+
#### Setting values on custom elements {/*attributes-vs-properties*/}
170+
171+
Custom elements have two methods of passing data into them:
172+
173+
1) Attributes: Which are displayed in markup and can only be set to string values
174+
2) Properties: Which are not displayed in markup and can be set to arbitrary JavaScript values
175+
176+
By default, React will pass values bound in JSX as attributes:
177+
178+
```jsx
179+
<my-element value="Hello, world!"></my-element>
180+
```
181+
182+
Non-string JavaScript values passed to custom elements will be serialized by default:
183+
184+
```jsx
185+
// Will be passed as `"1,2,3"` as the output of `[1,2,3].toString()`
186+
<my-element value={[1,2,3]}></my-element>
187+
```
188+
189+
React will, however, recognize an custom element's property as one that it may pass arbitrary values to if the property name shows up on the class during construction:
190+
191+
<Sandpack>
192+
193+
```js src/index.js hidden
194+
import {MyElement} from './MyElement.js';
195+
import { createRoot } from 'react-dom/client';
196+
import {App} from "./App.js";
197+
198+
customElements.define('my-element', MyElement);
199+
200+
const root = createRoot(document.getElementById('root'))
201+
root.render(<App />);
202+
```
203+
204+
```js src/MyElement.js active
205+
export class MyElement extends HTMLElement {
206+
constructor() {
207+
super();
208+
// The value here will be overwritten by React
209+
// when initialized as an element
210+
this.value = undefined;
211+
}
212+
213+
connectedCallback() {
214+
this.innerHTML = this.value.join(", ");
215+
}
216+
}
217+
```
173218

174-
[A future version of React will include more comprehensive support for custom elements.](https://github.com/facebook/react/issues/11347#issuecomment-1122275286)
219+
```js src/App.js
220+
export function App() {
221+
return <my-element value={[1,2,3]}></my-element>
222+
}
223+
```
175224

176-
You can try it by upgrading React packages to the most recent experimental version:
225+
</Sandpack>
226+
227+
#### Listening for events on custom elements {/*custom-element-events*/}
228+
229+
A common pattern when using custom elements is that they may dispatch [`CustomEvent`s](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) rather than accept a function to call when an event occur. You can listen for these events using an `on` prefix when binding to the event via JSX.
230+
231+
<Sandpack>
232+
233+
```js src/index.js hidden
234+
import {MyElement} from './MyElement.js';
235+
import { createRoot } from 'react-dom/client';
236+
import {App} from "./App.js";
237+
238+
customElements.define('my-element', MyElement);
239+
240+
const root = createRoot(document.getElementById('root'))
241+
root.render(<App />);
242+
```
243+
244+
```javascript src/MyElement.js
245+
export class MyElement extends HTMLElement {
246+
constructor() {
247+
super();
248+
this.test = undefined;
249+
this.emitEvent = this._emitEvent.bind(this);
250+
}
251+
252+
_emitEvent() {
253+
const event = new CustomEvent('speak', {
254+
detail: {
255+
message: 'Hello, world!',
256+
},
257+
});
258+
this.dispatchEvent(event);
259+
}
260+
261+
connectedCallback() {
262+
this.el = document.createElement('button');
263+
this.el.innerText = 'Say hi';
264+
this.el.addEventListener('click', this.emitEvent);
265+
this.appendChild(this.el);
266+
}
267+
268+
disconnectedCallback() {
269+
this.el.removeEventListener('click', this.emitEvent);
270+
}
271+
}
272+
```
273+
274+
```jsx src/App.js active
275+
export function App() {
276+
return (
277+
<my-element
278+
onspeak={e => console.log(e.detail.message)}
279+
></my-element>
280+
)
281+
}
282+
```
283+
284+
</Sandpack>
285+
286+
<Note>
177287

178-
- `react@experimental`
179-
- `react-dom@experimental`
288+
Events are case-sensitive and support dashes (`-`). Preserve the casing of the event and include all dashes when listening for custom element's events:
180289

181-
Experimental versions of React may contain bugs. Don't use them in production.
290+
```jsx
291+
// Listens for `say-hi` events
292+
<my-element onsay-hi={console.log}></my-element>
293+
// Listens for `sayHi` events
294+
<my-element onsayHi={console.log}></my-element>
295+
```
182296

183297
</Note>
184298
---

src/content/reference/react/Activity.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ While hidden, children still re-render in response to new props, albeit at a low
5151

5252
When the boundary becomes <CodeStep step={3}>visible</CodeStep> again, React will reveal the children with their previous state restored, and re-create their Effects.
5353

54+
<<<<<<< HEAD
5455
In this way, Activity can thought of as a mechanism for rendering "background activity". Rather than completely discarding content that's likely to become visible again, you can use Activity to maintain and restore that content's UI and internal state, while ensuring hidden content has no unwanted side effects.
56+
=======
57+
In this way, Activity can be thought of as a mechanism for rendering "background activity". Rather than completely discarding content that's likely to become visible again, you can use Activity to maintain and restore that content's UI and internal state, while ensuring that your hidden content has no unwanted side effects.
58+
>>>>>>> 27d86ffe6ec82e3642c6490d2187bae2271020a4
5559
5660
[See more examples below.](#usage)
5761

@@ -62,15 +66,23 @@ In this way, Activity can thought of as a mechanism for rendering "background ac
6266

6367
#### Caveats {/*caveats*/}
6468

69+
<<<<<<< HEAD
6570
- When used with `<ViewTransition>`, hidden activities that reveal in a transition will activate an "enter" animation. Visible Activities hidden in a transition will activate an "exit" animation.
71+
=======
72+
- If an Activity is rendered inside of a [ViewTransition](/reference/react/ViewTransition), and it becomes visible as a result of an update caused by [startTransition](/reference/react/startTransition), it will activate the ViewTransition's `enter` animation. If it becomes hidden, it will activate its `exit` animation.
73+
>>>>>>> 27d86ffe6ec82e3642c6490d2187bae2271020a4
6674
6775
---
6876

6977
## Usage {/*usage*/}
7078

7179
### Restoring the state of hidden components {/*restoring-the-state-of-hidden-components*/}
7280

81+
<<<<<<< HEAD
7382
Typically in React, when you want to conditionally show or hide a component, you mount and unmount it:
83+
=======
84+
In React, when you want to conditionally show or hide a component, you typically mount or unmount it based on that condition:
85+
>>>>>>> 27d86ffe6ec82e3642c6490d2187bae2271020a4
7486
7587
```jsx
7688
{isShowingSidebar && (
@@ -88,11 +100,19 @@ When you hide a component using an Activity boundary instead, React will "save"
88100
</Activity>
89101
```
90102

103+
<<<<<<< HEAD
91104
This makes it possible to restore components to their previous state.
92105

93106
The following example has a sidebar with an expandable section – you can press "Overview" to reveal the three subitems below it. The main app area also has a button that hides and shows the sidebar.
94107

95108
Try expanding the Overview section, then toggling the sidebar closed and open:
109+
=======
110+
This makes it possible to hide and then later restore components in the state they were previously in.
111+
112+
The following example has a sidebar with an expandable section. You can press "Overview" to reveal the three subitems below it. The main app area also has a button that hides and shows the sidebar.
113+
114+
Try expanding the Overview section, and then toggling the sidebar closed then open:
115+
>>>>>>> 27d86ffe6ec82e3642c6490d2187bae2271020a4
96116
97117
<Sandpack>
98118

src/sidebarHome.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,17 @@
1515
"path": "/learn/installation"
1616
},
1717
{
18+
<<<<<<< HEAD
1819
"title": "کامپایلر ری‌اکت",
1920
"path": "/learn/react-compiler"
21+
=======
22+
"title": "React Compiler",
23+
"path": "/learn/react-compiler"
24+
},
25+
{
26+
"hasSectionHeader": true,
27+
"sectionHeader": "LEARN REACT"
28+
>>>>>>> 27d86ffe6ec82e3642c6490d2187bae2271020a4
2029
},
2130
{
2231
"hasSectionHeader": true,
@@ -80,7 +89,27 @@
8089
},
8190
{
8291
"hasSectionHeader": true,
92+
<<<<<<< HEAD
8393
"sectionHeader": "API کامپایلر ری‌اکت"
94+
=======
95+
"sectionHeader": "REACT COMPILER API"
96+
},
97+
{
98+
"title": "Configuration",
99+
"path": "/reference/react-compiler/configuration"
100+
},
101+
{
102+
"title": "Directives",
103+
"path": "/reference/react-compiler/directives"
104+
},
105+
{
106+
"title": "Compiling Libraries",
107+
"path": "/reference/react-compiler/compiling-libraries"
108+
},
109+
{
110+
"hasSectionHeader": true,
111+
"sectionHeader": "GET INVOLVED"
112+
>>>>>>> 27d86ffe6ec82e3642c6490d2187bae2271020a4
84113
},
85114
{
86115
"title": "پیکربندی",

src/sidebarLearn.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@
5757
]
5858
},
5959
{
60+
<<<<<<< HEAD
6061
"title": "کامپایلر ری‌اکت",
62+
=======
63+
"title": "React Compiler",
64+
>>>>>>> 27d86ffe6ec82e3642c6490d2187bae2271020a4
6165
"path": "/learn/react-compiler",
6266
"canary": true,
6367
"routes": [
6468
{
69+
<<<<<<< HEAD
6570
"title": "مقدمه",
6671
"path": "/learn/react-compiler/introduction"
6772
},
@@ -75,6 +80,21 @@
7580
},
7681
{
7782
"title": "دیباگ و رفع اشکال",
83+
=======
84+
"title": "Introduction",
85+
"path": "/learn/react-compiler/introduction"
86+
},
87+
{
88+
"title": "Installation",
89+
"path": "/learn/react-compiler/installation"
90+
},
91+
{
92+
"title": "Incremental Adoption",
93+
"path": "/learn/react-compiler/incremental-adoption"
94+
},
95+
{
96+
"title": "Debugging and Troubleshooting",
97+
>>>>>>> 27d86ffe6ec82e3642c6490d2187bae2271020a4
7898
"path": "/learn/react-compiler/debugging"
7999
}
80100
]

0 commit comments

Comments
 (0)