Skip to content

Commit

Permalink
[learn] Clarify optional chaining in React components tutorial (#28864)
Browse files Browse the repository at this point in the history
* Update index.md with typo

Removed typo on line no.265

* Update files/en-us/learn/tools_and_testing/client-side_javascript_frameworks/react_components/index.md

Co-authored-by: Brian Thomas Smith <[email protected]>

* Update files/en-us/learn/tools_and_testing/client-side_javascript_frameworks/react_components/index.md

Co-authored-by: Brian Thomas Smith <[email protected]>

---------

Co-authored-by: Brian Thomas Smith <[email protected]>
  • Loading branch information
Fuzail22 and bsmth authored Aug 31, 2023
1 parent ac8770e commit e34ad42
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ This array is now available to the App component as `props.tasks`. You can `cons

To render our array of objects, we have to turn each object into a `<Todo />` component. JavaScript gives us an array method for transforming items into something else: [`Array.prototype.map()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).

Above the return statement of `App()`, make a new `const` called `taskList`. Let's start by transforming each task in the `props.tasks` array into its `name`:
Above the return statement of `App()`, make a new `const` called `taskList`. Let's start by transforming each task in the `props.tasks` array into its `name`.
The `?.` operator let's us perform [optional chaining](/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) to check if `props.tasks` is `undefined` or `null` before attempting to create a new array of task names:

```jsx
const taskList = props.tasks?.map((task) => task.name);
Expand Down

0 comments on commit e34ad42

Please sign in to comment.