From 0122c9aa8ca010df5420abaa174a675d0ed75c9a Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 5 Sep 2022 04:01:18 +0100 Subject: [PATCH] [Beta] Use h4 for Challenge titles (#4980) --- .../components/MDX/Challenges/Challenges.tsx | 2 +- beta/src/pages/apis/react/useContext.md | 14 +++++------ beta/src/pages/apis/react/useReducer.md | 10 ++++---- beta/src/pages/apis/react/useRef.md | 12 +++++----- beta/src/pages/apis/react/useState.md | 24 +++++++++---------- .../learn/choosing-the-state-structure.md | 8 +++---- beta/src/pages/learn/conditional-rendering.md | 6 ++--- .../extracting-state-logic-into-a-reducer.md | 8 +++---- .../importing-and-exporting-components.md | 2 +- .../javascript-in-jsx-with-curly-braces.md | 6 ++--- .../pages/learn/keeping-components-pure.md | 6 ++--- .../learn/lifecycle-of-reactive-effects.md | 10 ++++---- .../learn/manipulating-the-dom-with-refs.md | 8 +++---- .../learn/passing-data-deeply-with-context.md | 2 +- .../learn/passing-props-to-a-component.md | 6 ++--- .../learn/preserving-and-resetting-state.md | 10 ++++---- .../queueing-a-series-of-state-updates.md | 4 ++-- .../learn/reacting-to-input-with-state.md | 6 ++--- .../learn/referencing-values-with-refs.md | 8 +++---- .../learn/removing-effect-dependencies.md | 8 +++---- beta/src/pages/learn/rendering-lists.md | 8 +++---- beta/src/pages/learn/responding-to-events.md | 4 ++-- .../learn/reusing-logic-with-custom-hooks.md | 10 ++++---- .../learn/separating-events-from-effects.md | 8 +++---- .../learn/sharing-state-between-components.md | 4 ++-- .../pages/learn/state-a-components-memory.md | 8 +++---- beta/src/pages/learn/state-as-a-snapshot.md | 2 +- .../pages/learn/synchronizing-with-effects.md | 8 +++---- .../pages/learn/updating-arrays-in-state.md | 8 +++---- .../pages/learn/updating-objects-in-state.md | 6 ++--- .../pages/learn/writing-markup-with-jsx.md | 2 +- .../learn/you-might-not-need-an-effect.md | 8 +++---- beta/src/pages/learn/your-first-component.md | 8 +++---- 33 files changed, 122 insertions(+), 122 deletions(-) diff --git a/beta/src/components/MDX/Challenges/Challenges.tsx b/beta/src/components/MDX/Challenges/Challenges.tsx index 2474a466..64322feb 100644 --- a/beta/src/components/MDX/Challenges/Challenges.tsx +++ b/beta/src/components/MDX/Challenges/Challenges.tsx @@ -51,7 +51,7 @@ const parseChallengeContents = ( challenge.hint = child; break; } - case 'h3': { + case 'h4': { challenge.order = contents.length + 1; challenge.name = props.children; challenge.id = props.id; diff --git a/beta/src/pages/apis/react/useContext.md b/beta/src/pages/apis/react/useContext.md index 5b62530f..207a5fe2 100644 --- a/beta/src/pages/apis/react/useContext.md +++ b/beta/src/pages/apis/react/useContext.md @@ -177,7 +177,7 @@ Now any `Button` inside of the provider will receive the current `theme` value. -### Updating a value via context {/*updating-a-value-via-context*/} +#### Updating a value via context {/*updating-a-value-via-context*/} In this example, the `MyApp` component holds a state variable which is then passed to the `ThemeContext` provider. Checking the "Dark mode" checkbox updates the state. Changing the provided value re-renders all the components using that context. @@ -281,7 +281,7 @@ Note that `value="dark"` passes the `"dark"` string, but `value={theme}` passes -### Updating an object via context {/*updating-an-object-via-context*/} +#### Updating an object via context {/*updating-an-object-via-context*/} In this example, there is a `currentUser` state variable which holds an object. You combine `{ currentUser, setCurrentUser }` into a single object and pass it down through the context inside the `value={}`. This lets any component below, such as `LoginButton`, read both `currentUser` and `setCurrentUser`, and then call `setCurrentUser` when needed. @@ -373,7 +373,7 @@ label { -### Multiple contexts {/*multiple-contexts*/} +#### Multiple contexts {/*multiple-contexts*/} In this example, there are two independent contexts. `ThemeContext` provides the current theme, which is a string, while `CurrentUserContext` holds the object representing the current user. @@ -540,7 +540,7 @@ label { -### Extracting providers to a component {/*extracting-providers-to-a-component*/} +#### Extracting providers to a component {/*extracting-providers-to-a-component*/} As your app grows, it is expected that you'll have a "pyramid" of contexts closer to the root of your app. There is nothing wrong with that. However, if you dislike the nesting aesthetically, you can extract the providers into a single component. In this example, `MyProviders` hides the "plumbing" and renders the children passed to it inside the necessary providers. Note that the `theme` and `setTheme` state is needed in `MyApp` itself, so `MyApp` still owns that piece of the state. @@ -715,7 +715,7 @@ label { -### Scaling up with context and a reducer {/*scaling-up-with-context-and-a-reducer*/} +#### Scaling up with context and a reducer {/*scaling-up-with-context-and-a-reducer*/} In larger apps, it is common to combine context with a [reducer](/apis/react/useReducer) to extract the logic related to some state out of components. In this example, all the "wiring" is hidden in the `TasksContext.js`, which contains a reducer and two separate contexts. @@ -1058,7 +1058,7 @@ You can nest and override providers as many times as you need. -### Overriding a theme {/*overriding-a-theme*/} +#### Overriding a theme {/*overriding-a-theme*/} Here, the button *inside* the `Footer` receives a different context value (`"light"`) than the buttons outside (`"dark"`). @@ -1164,7 +1164,7 @@ footer { -### Automatically nested headings {/*automatically-nested-headings*/} +#### Automatically nested headings {/*automatically-nested-headings*/} You can "accumulate" information when you nest context providers. In this example, the `Section` component keeps track of the `LevelContext` which specifies the depth of the section nesting. It reads the `LevelContext` from the parent section, and provides the `LevelContext` number increased by one to its children. As a result, the `Heading` component can automatically decide which of the `

`, `

`, `

`, ..., tags to use based on how many `Section` components it is nested inside of. diff --git a/beta/src/pages/apis/react/useReducer.md b/beta/src/pages/apis/react/useReducer.md index a4b17b17..08edcdbd 100644 --- a/beta/src/pages/apis/react/useReducer.md +++ b/beta/src/pages/apis/react/useReducer.md @@ -191,7 +191,7 @@ Read [updating objects in state](/learn/updating-objects-in-state) and [updating -### Form (object) {/*form-object*/} +#### Form (object) {/*form-object*/} In this example, the reducer manages a state object with two fields: `name` and `age`. @@ -257,7 +257,7 @@ button { display: block; margin-top: 10px; } -### Todo list (array) {/*todo-list-array*/} +#### Todo list (array) {/*todo-list-array*/} In this example, the reducer manages an array of tasks. The array needs to be updated [without mutation](/learn/updating-arrays-in-state). @@ -450,7 +450,7 @@ ul, li { margin: 0; padding: 0; } -### Writing concise update logic with Immer {/*writing-concise-update-logic-with-immer*/} +#### Writing concise update logic with Immer {/*writing-concise-update-logic-with-immer*/} If updating arrays and objects without mutation feels tedious, you can use a library like [Immer](https://github.com/immerjs/use-immer#useimmerreducer) to reduce repetitive code. Immer lets you write concise code as if you were mutating objects, but under the hood it performs immutable updates: @@ -698,7 +698,7 @@ In the above example, `createInitialState` takes a `username` argument. If your -### Passing the initializer function {/*passing-the-initializer-function*/} +#### Passing the initializer function {/*passing-the-initializer-function*/} This example passes the initializer function, so the `createInitialState` function only runs during initialization. It does not run when component re-renders, such as when you type into the input. @@ -786,7 +786,7 @@ export default function TodoList({ username }) { -### Passing the initial state directly {/*passing-the-initial-state-directly*/} +#### Passing the initial state directly {/*passing-the-initial-state-directly*/} This example **does not** pass the initializer function, so the `createInitialState` function runs on every render, such as when you type into the input. There is no observable difference in behavior, but this code is less efficient. diff --git a/beta/src/pages/apis/react/useRef.md b/beta/src/pages/apis/react/useRef.md index 9dec4de1..23d2d25d 100644 --- a/beta/src/pages/apis/react/useRef.md +++ b/beta/src/pages/apis/react/useRef.md @@ -71,7 +71,7 @@ Changing a ref does not trigger a re-render, so refs are not appropriate for sto -### Click counter {/*click-counter*/} +#### Click counter {/*click-counter*/} This component uses a ref to keep track of how many times the button was clicked. Note that it's okay to use a ref instead of state here because the click count is only read and written in an event handler. @@ -102,7 +102,7 @@ If you show `{ref.current}` in the JSX, the number won't update on click. This i -### A stopwatch {/*a-stopwatch*/} +#### A stopwatch {/*a-stopwatch*/} This example uses a combination of state and refs. Both `startTime` and `now` are state variables because they are used for rendering. But we also need to hold an [interval ID](https://developer.mozilla.org/en-US/docs/Web/API/setInterval) so that we can stop the interval on button press. Since the interval ID is not used for rendering, it's appropriate to keep it in a ref, and manually update it. @@ -238,7 +238,7 @@ Read more about [manipulating the DOM with refs](/learn/manipulating-the-dom-wit -### Focusing a text input {/*focusing-a-text-input*/} +#### Focusing a text input {/*focusing-a-text-input*/} In this example, clicking the button will focus the input: @@ -269,7 +269,7 @@ export default function Form() { -### Scrolling an image into view {/*scrolling-an-image-into-view*/} +#### Scrolling an image into view {/*scrolling-an-image-into-view*/} In this example, clicking the button will scroll an image into view. It uses a ref to the list DOM node, and then calls DOM [`querySelectorAll`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll) API to find the image we want to scroll to. @@ -362,7 +362,7 @@ li { -### Playing and pausing a video {/*playing-and-pausing-a-video*/} +#### Playing and pausing a video {/*playing-and-pausing-a-video*/} This example uses a ref to call [`play()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play) and [`pause()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/pause) on a ` -### Write an expression inside JSX curly braces {/*write-an-expression-inside-jsx-curly-braces*/} +#### Write an expression inside JSX curly braces {/*write-an-expression-inside-jsx-curly-braces*/} In the object below, the full image URL is split into four parts: base URL, `imageId`, `imageSize`, and file extension. diff --git a/beta/src/pages/learn/keeping-components-pure.md b/beta/src/pages/learn/keeping-components-pure.md index 91914fb6..e53e92b1 100644 --- a/beta/src/pages/learn/keeping-components-pure.md +++ b/beta/src/pages/learn/keeping-components-pure.md @@ -225,7 +225,7 @@ Every new React feature we're building takes advantage of purity. From data fetc -### Fix a broken clock {/*fix-a-broken-clock*/} +#### Fix a broken clock {/*fix-a-broken-clock*/} This component tries to set the `

`'s CSS class to `"night"` during the time from midnight to six hours in the morning, and `"day"` at all other times. However, it doesn't work. Can you fix this component? @@ -362,7 +362,7 @@ In this example, the side effect (modifying the DOM) was not necessary at all. Y -### Fix a broken profile {/*fix-a-broken-profile*/} +#### Fix a broken profile {/*fix-a-broken-profile*/} Two `Profile` components are rendered side by side with different data. Press "Collapse" on the first profile, and then "Expand" it. You'll notice that both profiles now show the same person. This is a bug. @@ -571,7 +571,7 @@ Remember that React does not guarantee that component functions will execute in -### Fix a broken story tray {/*fix-a-broken-story-tray*/} +#### Fix a broken story tray {/*fix-a-broken-story-tray*/} The CEO of your company is asking you to add "stories" to your online clock app, and you can't say no. You've written a `StoryTray` component that accepts a list of `stories`, followed by a "Create Story" placeholder. diff --git a/beta/src/pages/learn/lifecycle-of-reactive-effects.md b/beta/src/pages/learn/lifecycle-of-reactive-effects.md index 4fb1c441..0f785e3f 100644 --- a/beta/src/pages/learn/lifecycle-of-reactive-effects.md +++ b/beta/src/pages/learn/lifecycle-of-reactive-effects.md @@ -769,7 +769,7 @@ On the [next](/learn/separating-events-from-effects) [pages](/learn/removing-eff -### Fix reconnecting on every keystroke {/*fix-reconnecting-on-every-keystroke*/} +#### Fix reconnecting on every keystroke {/*fix-reconnecting-on-every-keystroke*/} In this example, the `ChatRoom` component connects to the chat room when the component mounts, disconnects when it unmounts, and reconnects when you select a different chat room. This behavior is correct, so you need to keep it working. @@ -929,7 +929,7 @@ button { margin-left: 10px; } -### Switch synchronization on and off {/*switch-synchronization-on-and-off*/} +#### Switch synchronization on and off {/*switch-synchronization-on-and-off*/} In this example, an Effect subscribes to the window [`pointermove`](https://developer.mozilla.org/en-US/docs/Web/API/Element/pointermove_event) event to move a pink dot on the screen. Try hovering over the preview area (or touching the screen if you're on a mobile device), and see how the pink dot follows your movement. @@ -1111,7 +1111,7 @@ In both of these cases, `canMove` is a reactive variable that you read inside th -### Investigate a stale value bug {/*investigate-a-stale-value-bug*/} +#### Investigate a stale value bug {/*investigate-a-stale-value-bug*/} In this example, the pink dot should move when the checkbox if on, and should stop moving when the checkbox is off. The logic for this has already been implemented: the `handleMove` event handler checks the `canMove` state variable. @@ -1309,7 +1309,7 @@ You'll learn a more general approach to this type of problem in [Separating Even -### Fix a connection switch {/*fix-a-connection-switch*/} +#### Fix a connection switch {/*fix-a-connection-switch*/} In this example, the chat service in `chat.js` exposes two different APIs: `createEncryptedConnection` and `createUnencryptedConnection`. The root `App` component lets the user choose whether to use encryption or not, and then passes down the corresponding API method to the child `ChatRoom` component as the `createConnection` prop. @@ -1611,7 +1611,7 @@ In this version, the `App` component passes a boolean prop instead of a function -### Populate a chain of select boxes {/*populate-a-chain-of-select-boxes*/} +#### Populate a chain of select boxes {/*populate-a-chain-of-select-boxes*/} In this example, there are two select boxes. One select box lets the user picks a planet. Another select box lets the user pick a place *on that planet.* The second box doesn't work yet. Your task is to make it show the places on the chosen planet. diff --git a/beta/src/pages/learn/manipulating-the-dom-with-refs.md b/beta/src/pages/learn/manipulating-the-dom-with-refs.md index a9d164a5..ae2de41b 100644 --- a/beta/src/pages/learn/manipulating-the-dom-with-refs.md +++ b/beta/src/pages/learn/manipulating-the-dom-with-refs.md @@ -694,7 +694,7 @@ However, this doesn't mean that you can't do it at all. It requires caution. **Y -### Play and pause the video {/*play-and-pause-the-video*/} +#### Play and pause the video {/*play-and-pause-the-video*/} In this example, the button toggles a state variable to switch between a playing and a paused state. However, in order to actually play or pause the video, toggling state is not enough. You also need to call [`play()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play) and [`pause()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/pause) on the DOM element for the `