diff --git a/src/content/learn/tutorial-tic-tac-toe.md b/src/content/learn/tutorial-tic-tac-toe.md index 115c2a9a5..635d96f3b 100644 --- a/src/content/learn/tutorial-tic-tac-toe.md +++ b/src/content/learn/tutorial-tic-tac-toe.md @@ -1,31 +1,31 @@ --- -title: 'Tutorial: Tic-Tac-Toe' +title: 'آموزش: Tic-Tac-Toe' --- -You will build a small tic-tac-toe game during this tutorial. This tutorial does not assume any existing React knowledge. The techniques you'll learn in the tutorial are fundamental to building any React app, and fully understanding it will give you a deep understanding of React. +در طول این آموزش، یک بازی دوز کوچک خواهید ساخت. این آموزش فرض نمی‌کند که شما از قبل دانشی درباره ری‌اکت دارید. تکنیک‌هایی که در این آموزش یاد می‌گیرید، برای ساخت هر اپ ری‌اکت اساسی هستند و درک کامل آن به شما درک عمیقی از ری‌اکت خواهد داد. -This tutorial is designed for people who prefer to **learn by doing** and want to quickly try making something tangible. If you prefer learning each concept step by step, start with [Describing the UI.](/learn/describing-the-ui) +این آموزش برای افرادی طراحی شده است که ترجیح می‌دهند با **انجام دادن** یاد بگیرند و می‌خواهند به سرعت چیزی ملموس بسازند. اگر ترجیح می‌دهید هر مفهوم را گام به گام یاد بگیرید، با [توصیف رابط کاربری](/learn/describing-the-ui) شروع کنید. -The tutorial is divided into several sections: +آموزش به چندین بخش تقسیم شده است: -- [Setup for the tutorial](#setup-for-the-tutorial) will give you **a starting point** to follow the tutorial. -- [Overview](#overview) will teach you **the fundamentals** of React: components, props, and state. -- [Completing the game](#completing-the-game) will teach you **the most common techniques** in React development. -- [Adding time travel](#adding-time-travel) will give you **a deeper insight** into the unique strengths of React. +- [راه‌اندازی برای آموزش](#setup-for-the-tutorial) به شما **نقطه شروعی** برای دنبال کردن آموزش ارائه می‌دهد. +- [مرور کلی](#overview) به شما **اصول اولیه** ری‌اکت را آموزش می‌دهد: کامپوننت‌ها، props و state. +- [تکمیل بازی](#completing-the-game) به شما **رایج‌ترین تکنیک‌ها** در توسعه ری‌اکت را آموزش می‌دهد. +- [افزودن سفر در زمان](#adding-time-travel) به شما **بینش عمیق‌تری** از نقاط قوت منحصربه‌فرد ری‌اکت می‌دهد. -### What are you building? {/*what-are-you-building*/} +### چه چیزی می‌سازید؟ {/*what-are-you-building*/} -In this tutorial, you'll build an interactive tic-tac-toe game with React. +در این آموزش، یک بازی تیک‌تاک‌تو تعاملی با ری‌اکت می‌سازید. -You can see what it will look like when you're finished here: +می‌توانید ببینید که وقتی کارتان تمام شد، چگونه به نظر می‌رسد: @@ -194,15 +194,15 @@ body { -If the code doesn't make sense to you yet, or if you are unfamiliar with the code's syntax, don't worry! The goal of this tutorial is to help you understand React and its syntax. +اگر کد هنوز برای شما قابل فهم نیست یا با نحو کد آشنا نیستید، نگران نباشید! هدف این آموزش این است که به شما کمک کند ری‌اکت و نحو آن را بفهمید. -We recommend that you check out the tic-tac-toe game above before continuing with the tutorial. One of the features that you'll notice is that there is a numbered list to the right of the game's board. This list gives you a history of all of the moves that have occurred in the game, and it is updated as the game progresses. +ما توصیه می‌کنیم که قبل از ادامه آموزش، بازی دوز بالا را بررسی کنید. یکی از قابلیت‌هایی که متوجه خواهید شد این است که یک لیست شماره‌گذاری‌شده در سمت راست صفحه بازی وجود دارد. این لیست تاریخچه‌ای از تمام حرکاتی که در بازی انجام شده را نشان می‌دهد و با پیشرفت بازی به‌روزرسانی می‌شود. -Once you've played around with the finished tic-tac-toe game, keep scrolling. You'll start with a simpler template in this tutorial. Our next step is to set you up so that you can start building the game. +پس از اینکه با بازی کامل‌شده دوز بازی کردید، به پایین اسکرول کنید. در این آموزش با یک قالب ساده‌تر شروع خواهید کرد. گام بعدی ما این است که شما را آماده کنیم تا بتوانید ساخت بازی را آغاز کنید. -## Setup for the tutorial {/*setup-for-the-tutorial*/} +## راه‌اندازی برای آموزش {/*setup-for-the-tutorial*/} -In the live code editor below, click **Fork** in the top-right corner to open the editor in a new tab using the website CodeSandbox. CodeSandbox lets you write code in your browser and preview how your users will see the app you've created. The new tab should display an empty square and the starter code for this tutorial. +در ویرایشگر کد زنده زیر، روی **Fork** در گوشه بالا-راست کلیک کنید تا ویرایشگر در یک تب جدید با استفاده از وب‌سایت CodeSandbox باز شود. CodeSandbox به شما اجازه می‌دهد کد را در مرورگر خود بنویسید و پیش‌نمایشی از نحوه مشاهده اپ توسط کاربران‌تان را ببینید. تب جدید باید یک مربع خالی و کد ابتدایی این آموزش را نمایش دهد. @@ -261,33 +261,33 @@ body { -You can also follow this tutorial using your local development environment. To do this, you need to: +شما همچنین می‌توانید این آموزش را با استفاده از محیط توسعه محلی خود دنبال کنید. برای انجام این کار، باید: -1. Install [Node.js](https://nodejs.org/en/) -1. In the CodeSandbox tab you opened earlier, press the top-left corner button to open the menu, and then choose **Download Sandbox** in that menu to download an archive of the files locally -1. Unzip the archive, then open a terminal and `cd` to the directory you unzipped -1. Install the dependencies with `npm install` -1. Run `npm start` to start a local server and follow the prompts to view the code running in a browser +1. [Node.js](https://nodejs.org/en/) را نصب کنید. +۱. در تب CodeSandbox که قبلاً باز کردید، دکمه گوشه بالا-چپ را فشار دهید تا منو باز شود، سپس در آن منو گزینه **Download Sandbox** را انتخاب کنید تا یک آرشیو از فایل‌ها را به‌صورت محلی دانلود کنید. +1. فایل فشرده را از حالت فشرده خارج کنید، سپس یک ترمینال باز کرده و `cd` به دایرکتوری که از حالت فشرده خارج کردید بروید. +1. وابستگی‌ها را با `npm install` نصب کنید. +1. `npm start` را اجرا کنید تا یک سرور محلی راه‌اندازی شود و دستورات را دنبال کنید تا کد را در مرورگر ببینید. -If you get stuck, don't let this stop you! Follow along online instead and try a local setup again later. +اگر گیر کردید، اجازه ندهید این موضوع شما را متوقف کند! به‌جای آن به‌صورت آنلاین ادامه دهید و بعداً دوباره یک راه‌اندازی محلی را امتحان کنید. -## Overview {/*overview*/} +## مرور کلی {/*overview*/} -Now that you're set up, let's get an overview of React! +حالا که آماده‌اید، بیایید مروری بر ری‌اکت داشته باشیم! -### Inspecting the starter code {/*inspecting-the-starter-code*/} +### بررسی کد شروع {/*inspecting-the-starter-code*/} -In CodeSandbox you'll see three main sections: +در CodeSandbox سه بخش اصلی مشاهده خواهید کرد: -![CodeSandbox with starter code](../images/tutorial/react-starter-code-codesandbox.png) +![CodeSandbox با کد آغازین](../images/tutorial/react-starter-code-codesandbox.png) -1. The _Files_ section with a list of files like `App.js`, `index.js`, `styles.css` in `src` folder and a folder called `public` -1. The _code editor_ where you'll see the source code of your selected file -1. The _browser_ section where you'll see how the code you've written will be displayed +1. بخش _Files_ با لیستی از فایل‌ها مانند `App.js`، `index.js`، `styles.css` در پوشه `src` و یک پوشه به نام `public` +1. ویرایشگر _کد_ که در آن کد منبع فایل انتخاب‌شده خود را مشاهده خواهید کرد +1. بخش _مرورگر_ که در آن خواهید دید کدی که نوشته‌اید چگونه نمایش داده می‌شود. -The `App.js` file should be selected in the _Files_ section. The contents of that file in the _code editor_ should be: +فایل `App.js` باید در بخش _Files_ انتخاب شود. محتوای آن فایل در _ویرایشگر کد_ باید به صورت زیر باشد: ```jsx export default function Square() { @@ -295,15 +295,15 @@ export default function Square() { } ``` -The _browser_ section should be displaying a square with an X in it like this: +بخش _مرورگر_ باید مربعی با یک X در آن نمایش دهد، مانند این: ![x-filled square](../images/tutorial/x-filled-square.png) -Now let's have a look at the files in the starter code. +حالا بیایید نگاهی به فایل‌های کد آغازین بیندازیم. #### `App.js` {/*appjs*/} -The code in `App.js` creates a _component_. In React, a component is a piece of reusable code that represents a part of a user interface. Components are used to render, manage, and update the UI elements in your application. Let's look at the component line by line to see what's going on: +کد در `App.js` یک _کامپوننت_ ایجاد می‌کند. در ری‌اکت، یک کامپوننت قطعه‌ای از کد قابل استفاده مجدد است که بخشی از رابط کاربری را نمایش می‌دهد. کامپوننت‌ها برای رندر، مدیریت و به‌روزرسانی المنت‌های رابط کاربری در برنامه شما استفاده می‌شوند. بیایید خط به خط به کامپوننت نگاه کنیم تا ببینیم چه اتفاقی می‌افتد: ```js {1} export default function Square() { @@ -311,7 +311,7 @@ export default function Square() { } ``` -The first line defines a function called `Square`. The `export` JavaScript keyword makes this function accessible outside of this file. The `default` keyword tells other files using your code that it's the main function in your file. +خط اول یک تابع به نام `Square` تعریف می‌کند. کلمه کلیدی `export` در جاوااسکریپت این تابع را در خارج از این فایل قابل دسترسی می‌کند. کلمه کلیدی `default` به فایل‌های دیگر که از کد شما استفاده می‌کنند می‌گوید که این تابع اصلی در فایل شما است. ```js {2} export default function Square() { @@ -319,15 +319,15 @@ export default function Square() { } ``` -The second line returns a button. The `return` JavaScript keyword means whatever comes after is returned as a value to the caller of the function. `` closes the JSX element to indicate that any following content shouldn't be placed inside the button. +خط دوم یک دکمه را برمی‌گرداند. کلمه کلیدی `return` در جاوااسکریپت به این معناست که هر چیزی که بعد از آن می‌آید به عنوان یک مقدار به فراخوان تابع برگردانده می‌شود. `` المنت JSX را می‌بندد تا نشان دهد که هر محتوای بعدی نباید داخل دکمه قرار گیرد. #### `styles.css` {/*stylescss*/} -Click on the file labeled `styles.css` in the _Files_ section of CodeSandbox. This file defines the styles for your React app. The first two _CSS selectors_ (`*` and `body`) define the style of large parts of your app while the `.square` selector defines the style of any component where the `className` property is set to `square`. In your code, that would match the button from your Square component in the `App.js` file. +روی فایلی که با `styles.css` برچسب‌گذاری شده است در بخش _Files_ از CodeSandbox کلیک کنید. این فایل، استایل‌های برنامه ری‌اکت شما را تعریف می‌کند. دو _CSS selector_ اول (`*` و `body`) استایل بخش‌های بزرگی از برنامه شما را تعریف می‌کنند، در حالی که سلکتور `.square` استایل هر کامپوننتی را که ویژگی `className` روی `square` تنظیم شده باشد، تعریف می‌کند. در کد شما، این با دکمه‌ای از کامپوننت Square در فایل `App.js` مطابقت دارد. #### `index.js` {/*indexjs*/} -Click on the file labeled `index.js` in the _Files_ section of CodeSandbox. You won't be editing this file during the tutorial but it is the bridge between the component you created in the `App.js` file and the web browser. +روی فایلی که با برچسب `index.js` در بخش _Files_ در CodeSandbox قرار دارد کلیک کنید. شما در طول این آموزش این فایل را ویرایش نخواهید کرد، اما این فایل پل ارتباطی بین کامپوننتی است که در فایل `App.js` ایجاد کرده‌اید و مرورگر وب است. ```jsx import { StrictMode } from 'react'; @@ -337,20 +337,20 @@ import './styles.css'; import App from './App'; ``` -Lines 1-5 bring all the necessary pieces together: +خطوط ۱-۵ تمام قطعات لازم را کنار هم می‌آورند: -* React -* React's library to talk to web browsers (React DOM) -* the styles for your components -* the component you created in `App.js`. +* ری‌اکت +* کتابخانه ری‌اکت برای ارتباط با مرورگرهای وب (React DOM) +* استایل‌ها برای کامپوننت‌های شما +* کامپوننتی که در `App.js` ایجاد کرده‌اید. -The remainder of the file brings all the pieces together and injects the final product into `index.html` in the `public` folder. +باقی‌مانده فایل تمام قطعات را کنار هم قرار می‌دهد و محصول نهایی را در `index.html` در پوشه `public` وارد می‌کند. -### Building the board {/*building-the-board*/} +### ساخت تخته {/*building-the-board*/} -Let's get back to `App.js`. This is where you'll spend the rest of the tutorial. +بیایید به `App.js` برگردیم. اینجا جایی است که بقیهٔ آموزش را در آن سپری خواهید کرد. -Currently the board is only a single square, but you need nine! If you just try and copy paste your square to make two squares like this: +در حال حاضر، صفحه فقط یک مربع است، اما شما به نه مربع نیاز دارید! اگر فقط سعی کنید مربع خود را کپی و جای‌گذاری کنید تا دو مربع بسازید، به این صورت: ```js {2} export default function Square() { @@ -358,15 +358,15 @@ export default function Square() { } ``` -You'll get this error: +این خطا را دریافت می‌کنید: -/src/App.js: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX Fragment `<>...`? +/src/App.js: المنت‌های JSX مجاور باید در یک تگ محصورکننده قرار گیرند. آیا می‌خواهید از یک فرگمنت JSX `<>...` استفاده کنید؟ -React components need to return a single JSX element and not multiple adjacent JSX elements like two buttons. To fix this you can use *Fragments* (`<>` and ``) to wrap multiple adjacent JSX elements like this: +کامپوننت‌های ری‌اکت باید یک المنت JSX واحد برگردانند و نه چند المنت JSX مجاور مانند دو دکمه. برای رفع این مشکل می‌توانید از *فرگمنت‌ها* (`<>` و ``) برای محصور کردن چند المنت JSX مجاور به این صورت استفاده کنید: ```js {3-6} export default function Square() { @@ -379,17 +379,17 @@ export default function Square() { } ``` -Now you should see: +اکنون باید ببینید: -![two x-filled squares](../images/tutorial/two-x-filled-squares.png) +![دو مربع پر شده با X](../images/tutorial/two-x-filled-squares.png) -Great! Now you just need to copy-paste a few times to add nine squares and... +عالی! حالا فقط باید چند بار کپی-پیست کنید تا نه مربع اضافه شود و... -![nine x-filled squares in a line](../images/tutorial/nine-x-filled-squares.png) +![نه مربع پر شده با X در یک خط](../images/tutorial/nine-x-filled-squares.png) -Oh no! The squares are all in a single line, not in a grid like you need for our board. To fix this you'll need to group your squares into rows with `div`s and add some CSS classes. While you're at it, you'll give each square a number to make sure you know where each square is displayed. +اوه نه! مربع‌ها همه در یک خط قرار دارند، نه به صورت شبکه‌ای که برای تخته‌مان نیاز داریم. برای رفع این مشکل، باید مربع‌هایتان را با استفاده از `div`ها به ردیف‌ها گروه‌بندی کنید و چند کلاس CSS اضافه کنید. در همین حین، به هر مربع یک شماره بدهید تا مطمئن شوید که می‌دانید هر مربع کجا نمایش داده می‌شود. -In the `App.js` file, update the `Square` component to look like this: +در فایل `App.js`، کامپوننت `Square` را به این شکل به‌روزرسانی کنید: ```js {3-19} export default function Square() { @@ -415,11 +415,11 @@ export default function Square() { } ``` -The CSS defined in `styles.css` styles the divs with the `className` of `board-row`. Now that you've grouped your components into rows with the styled `div`s you have your tic-tac-toe board: +CSS تعریف‌شده در `styles.css`، divها را با `className` `board-row` استایل می‌دهد. حالا که کامپوننت‌های خود را با `div`های استایل‌شده به ردیف‌ها گروه‌بندی کرده‌اید، تخته دوز خود را دارید: ![tic-tac-toe board filled with numbers 1 through 9](../images/tutorial/number-filled-board.png) -But you now have a problem. Your component named `Square`, really isn't a square anymore. Let's fix that by changing the name to `Board`: +اما اکنون یک مشکل دارید. کامپوننت شما با نام `Square` دیگر واقعاً یک مربع نیست. بیایید با تغییر نام آن به `Board` این مشکل را برطرف کنیم: ```js {1} export default function Board() { @@ -427,7 +427,7 @@ export default function Board() { } ``` -At this point your code should look something like this: +در این مرحله، کد شما باید به این شکل باشد: @@ -504,15 +504,15 @@ body { -Psssst... That's a lot to type! It's okay to copy and paste code from this page. However, if you're up for a little challenge, we recommend only copying code that you've manually typed at least once yourself. +پیسسس... این خیلی تایپ کردن می‌خواهد! اشکالی ندارد که کد را از این صفحه کپی و پیست کنید. با این حال، اگر به دنبال یک چالش کوچک هستید، توصیه می‌کنیم فقط کدی را کپی کنید که حداقل یک بار خودتان به‌صورت دستی تایپ کرده‌اید. -### Passing data through props {/*passing-data-through-props*/} +### انتقال داده از طریق props {/*passing-data-through-props*/} -Next, you'll want to change the value of a square from empty to "X" when the user clicks on the square. With how you've built the board so far you would need to copy-paste the code that updates the square nine times (once for each square you have)! Instead of copy-pasting, React's component architecture allows you to create a reusable component to avoid messy, duplicated code. +در مرحله بعد، می‌خواهید با کلیک کاربر روی مربع، مقدار آن را از خالی به "X" تغییر دهید. با توجه به نحوه ساختن برد تا اینجا، باید کدی که مربع را به‌روزرسانی می‌کند را نه بار کپی-پیست کنید (یک بار برای هر مربع)! به جای کپی-پیست، معماری کامپوننت ری‌اکت به شما اجازه می‌دهد یک کامپوننت قابل استفاده مجدد ایجاد کنید تا از کدهای تکراری و نامرتب جلوگیری شود. -First, you are going to copy the line defining your first square (``) from your `Board` component into a new `Square` component: +ابتدا، خطی که مربع اول شما را تعریف می‌کند (``) از کامپوننت `Board` خود به یک کامپوننت جدید `Square` کپی کنید: ```js {1-3} function Square() { @@ -524,7 +524,7 @@ export default function Board() { } ``` -Then you'll update the Board component to render that `Square` component using JSX syntax: +سپس کامپوننت Board را به‌روزرسانی می‌کنید تا آن کامپوننت `Square` را با استفاده از سینتکس JSX رندر کنید: ```js {5-19} // ... @@ -551,15 +551,15 @@ export default function Board() { } ``` -Note how unlike the browser `div`s, your own components `Board` and `Square` must start with a capital letter. +توجه کنید که برخلاف `div`های مرورگر، کامپوننت‌های خودتان `Board` و `Square` باید با حرف بزرگ شروع شوند. -Let's take a look: +بیایید نگاهی بیندازیم: ![one-filled board](../images/tutorial/board-filled-with-ones.png) -Oh no! You lost the numbered squares you had before. Now each square says "1". To fix this, you will use *props* to pass the value each square should have from the parent component (`Board`) to its child (`Square`). +اوه نه! شما مربع‌های شماره‌دار قبلی خود را از دست داده‌اید. اکنون هر مربع "1" را نشان می‌دهد. برای رفع این مشکل، از *props* استفاده خواهید کرد تا مقداری که هر مربع باید داشته باشد را از کامپوننت والد (`Board`) به کامپوننت فرزند (`Square`) منتقل کنید. -Update the `Square` component to read the `value` prop that you'll pass from the `Board`: +کامپوننت `Square` را به‌روزرسانی کنید تا ویژگی `value` را که از `Board` ارسال می‌کنید، بخواند. ```js {1} function Square({ value }) { @@ -567,9 +567,9 @@ function Square({ value }) { } ``` -`function Square({ value })` indicates the Square component can be passed a prop called `value`. +`function Square({ value })` نشان می‌دهد که کامپوننت Square می‌تواند یک prop به نام `value` پاس داده شود. -Now you want to display that `value` instead of `1` inside every square. Try doing it like this: +حالا می‌خواهید آن `value` را به جای `1` درون هر مربع نمایش دهید. سعی کنید این کار را به این صورت انجام دهید: ```js {2} function Square({ value }) { @@ -577,11 +577,11 @@ function Square({ value }) { } ``` -Oops, this is not what you wanted: +اوه، این چیزی نیست که می‌خواستید: ![value-filled board](../images/tutorial/board-filled-with-value.png) -You wanted to render the JavaScript variable called `value` from your component, not the word "value". To "escape into JavaScript" from JSX, you need curly braces. Add curly braces around `value` in JSX like so: +شما می‌خواستید متغیر جاوااسکریپت به نام `value` را از کامپوننت خود رندر کنید، نه کلمه "value". برای "فرار به جاوااسکریپت" از JSX، به آکولاد نیاز دارید. آکولادها را در اطراف `value` در JSX اضافه کنید به این صورت: ```js {2} function Square({ value }) { @@ -589,11 +589,11 @@ function Square({ value }) { } ``` -For now, you should see an empty board: +فعلاً باید یک برد خالی ببینید: ![empty board](../images/tutorial/empty-board.png) -This is because the `Board` component hasn't passed the `value` prop to each `Square` component it renders yet. To fix it you'll add the `value` prop to each `Square` component rendered by the `Board` component: +این به این دلیل است که کامپوننت `Board` هنوز ویژگی `value` را به هر کامپوننت `Square` که رندر می‌کند، ارسال نکرده است. برای رفع این مشکل، ویژگی `value` را به هر کامپوننت `Square` که توسط کامپوننت `Board` رندر می‌شود، اضافه می‌کنید: ```js {5-7,10-12,15-17} export default function Board() { @@ -619,11 +619,11 @@ export default function Board() { } ``` -Now you should see a grid of numbers again: +حالا باید دوباره یک گرید از اعداد ببینید: ![tic-tac-toe board filled with numbers 1 through 9](../images/tutorial/number-filled-board.png) -Your updated code should look like this: +کد به‌روزشده شما باید به این صورت باشد: @@ -702,9 +702,9 @@ body { -### Making an interactive component {/*making-an-interactive-component*/} +### ساخت یک کامپوننت تعاملی {/*making-an-interactive-component*/} -Let's fill the `Square` component with an `X` when you click it. Declare a function called `handleClick` inside of the `Square`. Then, add `onClick` to the props of the button JSX element returned from the `Square`: +بیایید کامپوننت `Square` را با یک `X` زمانی که روی آن کلیک می‌کنید پر کنیم. یک تابع به نام `handleClick` درون `Square` تعریف کنید. سپس، `onClick` را به props المنت JSX دکمه‌ای که از `Square` برگردانده می‌شود اضافه کنید: ```js {2-4,9} function Square({ value }) { @@ -723,19 +723,19 @@ function Square({ value }) { } ``` -If you click on a square now, you should see a log saying `"clicked!"` in the _Console_ tab at the bottom of the _Browser_ section in CodeSandbox. Clicking the square more than once will log `"clicked!"` again. Repeated console logs with the same message will not create more lines in the console. Instead, you will see an incrementing counter next to your first `"clicked!"` log. +اگر اکنون روی یک مربع کلیک کنید، باید یک لاگ با عنوان `"clicked!"` را در تب _Console_ در بخش _Browser_ در CodeSandbox ببینید. کلیک کردن روی مربع بیش از یک بار، `"clicked!"` را دوباره لاگ می‌کند. لاگ‌های مکرر کنسول با همان پیام، خطوط بیشتری در کنسول ایجاد نمی‌کنند. در عوض، یک شمارنده افزایشی در کنار اولین لاگ `"clicked!"` خود خواهید دید. -If you are following this tutorial using your local development environment, you need to open your browser's Console. For example, if you use the Chrome browser, you can view the Console with the keyboard shortcut **Shift + Ctrl + J** (on Windows/Linux) or **Option + ⌘ + J** (on macOS). +اگر این آموزش را با استفاده از محیط توسعه محلی خود دنبال می‌کنید، باید کنسول مرورگر خود را باز کنید. به عنوان مثال، اگر از مرورگر Chrome استفاده می‌کنید، می‌توانید با استفاده از میانبر صفحه‌کلید **Shift + Ctrl + J** (در ویندوز/لینوکس) یا **Option + ⌘ + J** (در macOS) کنسول را مشاهده کنید. -As a next step, you want the Square component to "remember" that it got clicked, and fill it with an "X" mark. To "remember" things, components use *state*. +به عنوان گام بعدی، می‌خواهید کامپوننت Square "به خاطر بسپارد" که کلیک شده است و آن را با علامت "X" پر کند. برای "به خاطر سپردن" چیزها، کامپوننت‌ها از *state* استفاده می‌کنند. -React provides a special function called `useState` that you can call from your component to let it "remember" things. Let's store the current value of the `Square` in state, and change it when the `Square` is clicked. +ری‌اکت یک تابع ویژه به نام `useState` ارائه می‌دهد که می‌توانید از کامپوننت خود آن را فراخوانی کنید تا به آن اجازه دهید چیزهایی را "به خاطر بسپارد". بیایید مقدار فعلی `Square` را در state ذخیره کنیم و زمانی که `Square` کلیک شد، آن را تغییر دهیم. -Import `useState` at the top of the file. Remove the `value` prop from the `Square` component. Instead, add a new line at the start of the `Square` that calls `useState`. Have it return a state variable called `value`: +`useState` را در بالای فایل import کنید. ویژگی `value` را از کامپوننت `Square` حذف کنید. به جای آن، یک خط جدید در ابتدای `Square` اضافه کنید که `useState` را فراخوانی کند. این باید یک متغیر state به نام `value` برگرداند: ```js {1,3,4} import { useState } from 'react'; @@ -747,9 +747,9 @@ function Square() { //... ``` -`value` stores the value and `setValue` is a function that can be used to change the value. The `null` passed to `useState` is used as the initial value for this state variable, so `value` here starts off equal to `null`. +`value` مقدار را ذخیره می‌کند و `setValue` تابعی است که می‌توان از آن برای تغییر مقدار استفاده کرد. `null` که به `useState` ارسال می‌شود به عنوان مقدار اولیه برای این متغیر state استفاده می‌شود، بنابراین `value` در اینجا با `null` شروع می‌شود. -Since the `Square` component no longer accepts props anymore, you'll remove the `value` prop from all nine of the Square components created by the Board component: +از آنجا که کامپوننت `Square` دیگر props را نمی‌پذیرد، باید prop `value` را از هر نه کامپوننت Square که توسط کامپوننت Board ایجاد شده‌اند، حذف کنید: ```js {6-8,11-13,16-18} // ... @@ -776,7 +776,7 @@ export default function Board() { } ``` -Now you'll change `Square` to display an "X" when clicked. Replace the `console.log("clicked!");` event handler with `setValue('X');`. Now your `Square` component looks like this: +حالا با کلیک بر روی `Square`، یک "X" نمایش داده خواهد شد. event handler `console.log("clicked!");` را با `setValue('X');` جایگزین کنید. اکنون کامپوننت `Square` شما به این شکل است: ```js {5} function Square() { @@ -797,13 +797,13 @@ function Square() { } ``` -By calling this `set` function from an `onClick` handler, you're telling React to re-render that `Square` whenever its `