Skip to content

Commit 09d9eec

Browse files
authored
Merge pull request #2839 from romanstetsyk/part2b-links
update links to react docs for part2b
2 parents 756f70b + ad7d9b8 commit 09d9eec

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/content/2/en/part2b.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ lang: en
99

1010
Let's continue expanding our application by allowing users to add new notes. You can find the code for our current application [here](https://github.com/fullstack-hy2020/part2-notes/tree/part2-1).
1111

12-
To get our page to update when new notes are added it's best to store the notes in the <i>App</i> component's state. Let's import the [useState](https://reactjs.org/docs/hooks-state.html) function and use it to define a piece of state that gets initialized with the initial notes array passed in the props.
12+
To get our page to update when new notes are added it's best to store the notes in the <i>App</i> component's state. Let's import the [useState](https://react.dev/reference/react/useState) function and use it to define a piece of state that gets initialized with the initial notes array passed in the props.
1313

1414
```js
1515
import { useState } from 'react' // highlight-line
@@ -102,7 +102,7 @@ const addNote = (event) => {
102102
}
103103
```
104104

105-
The <em>event</em> parameter is the [event](https://reactjs.org/docs/handling-events.html) that triggers the call to the event handler function:
105+
The <em>event</em> parameter is the [event](https://react.dev/learn/responding-to-events) that triggers the call to the event handler function:
106106

107107
The event handler immediately calls the <em>event.preventDefault()</em> method, which prevents the default action of submitting a form. The default action would, [among other things](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit_event), cause the page to reload.
108108

@@ -116,7 +116,7 @@ How do we access the data contained in the form's <i>input</i> element?
116116

117117
### Controlled component
118118

119-
There are many ways to accomplish this; the first method we will take a look at is through the use of so-called [controlled components](https://reactjs.org/docs/forms.html#controlled-components).
119+
There are many ways to accomplish this; the first method we will take a look at is through the use of so-called [controlled components](https://react.dev/reference/react-dom/components/input#controlling-an-input-with-a-state-variable).
120120

121121
Let's add a new piece of state called <em>newNote</em> for storing the user-submitted input **and** let's set it as the <i>input</i> element's <i>value</i> attribute:
122122

@@ -155,7 +155,7 @@ The placeholder text stored as the initial value of the <em>newNote</em> state a
155155

156156
![provided value to prop without onchange console error](../../images/2/7e.png)
157157

158-
Since we assigned a piece of the <i>App</i> component's state as the <i>value</i> attribute of the input element, the <i>App</i> component now [controls](https://reactjs.org/docs/forms.html#controlled-components) the behavior of the input element.
158+
Since we assigned a piece of the <i>App</i> component's state as the <i>value</i> attribute of the input element, the <i>App</i> component now [controls](https://react.dev/reference/react-dom/components/input#controlling-an-input-with-a-state-variable) the behavior of the input element.
159159

160160
To enable editing of the input element, we have to register an <i>event handler</i> that synchronizes the changes made to the input with the component's state:
161161

@@ -249,7 +249,7 @@ The new note is added to the list of notes using the [concat](https://developer.
249249
setNotes(notes.concat(noteObject))
250250
```
251251

252-
The method does not mutate the original <em>notes</em> array, but rather creates <i>a new copy of the array with the new item added to the end</i>. This is important since we must [never mutate state directly](https://reactjs.org/docs/state-and-lifecycle.html#using-state-correctly) in React!
252+
The method does not mutate the original <em>notes</em> array, but rather creates <i>a new copy of the array with the new item added to the end</i>. This is important since we must [never mutate state directly](https://react.dev/learn/updating-objects-in-state#why-is-mutating-state-not-recommended-in-react) in React!
253253

254254
The event handler also resets the value of the controlled input element by calling the <em>setNewNote</em> function of the <em>newNote</em> state:
255255

0 commit comments

Comments
 (0)