Skip to content

Commit

Permalink
enhance learner experience πŸ› οΈβœ¨ and fix typos at errors module (#367)
Browse files Browse the repository at this point in the history
Co-authored-by: Kent C. Dodds <me@kentcdodds.com>
  • Loading branch information
moelzanaty3 and kentcdodds committed Apr 24, 2024
1 parent 601e5f6 commit a781787
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions exercises/08.errors/01.problem.composition/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ the `ErrorBoundary` so we can define our own `ErrorFallback` component.

Right now we have an `App` component which we render using
`ReactDOM.createRoot(rootEl).render(<App />)`, so to get our stuff wrapped
properly, we'll rename our existing `App` component (call it `Onboarding`) and
then make a new `App` which renders the `ErrorBoundary` around the `Onboarding`
properly, we'll rename our existing `App` component (call it `OnboardingForm`) and
then make a new `App` which renders the `ErrorBoundary` around the `OnboardingForm`
component along with our `FallbackComponent` called `ErrorFallback` (which you
also have to create).

Expand Down
3 changes: 2 additions & 1 deletion exercises/08.errors/01.problem.composition/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ReactDOM from 'react-dom/client'
// 🐨 bring in ErrorBoundary and FallbackProps from react-error-boundary
// 🐨 bring in ErrorBoundary and FallbackProps type from react-error-boundary

// 🐨 Rename this to OnboardingForm
function App() {
Expand Down Expand Up @@ -99,6 +99,7 @@ function App() {
// 🐨 create an ErrorFallback component here that accepts FallbackProps
// and renders the error.message
// πŸ’― you can make it look nice if you want
// πŸ“œ https://github.com/bvaughn/react-error-boundary#errorboundary-with-fallbackcomponent-prop

// 🐨 make a component called "App" that renders the OnboardingForm inside an
// ErrorBoundary with the ErrorFallback as the FallbackComponent
Expand Down
6 changes: 5 additions & 1 deletion exercises/08.errors/02.problem.show-boundary/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
πŸ‘¨β€πŸ’Ό Recall previously we learned that React doesn't catch all errors for you.
We've got an error in our `onSubmit` handler like this. If you try to submit the
form, you'll notice in the console that there's an error (someone made a typo
πŸ˜…).
πŸ˜…). The error looks something like:

> ```javascript
> Uncaught TypeError: Cannot read properties of null (reading 'toUpperCase')
> ```
Before we fix the typo, we want to give the user better feedback for when
something like this happens (right now, they don't know it's not working and
Expand Down
1 change: 1 addition & 0 deletions exercises/08.errors/02.problem.show-boundary/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ReactDOM from 'react-dom/client'
// 🐨 bring in useErrorBoundary from react-error-boundary
import { ErrorBoundary, type FallbackProps } from 'react-error-boundary'

function OnboardingForm() {
Expand Down
2 changes: 1 addition & 1 deletion exercises/08.errors/03.problem.reset/README.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Reset

πŸ‘¨β€πŸ’Ό Sometimes errors are temporary and will go away if you just "turn it off and
on again." `react-error-boudary` supports this with a `resetErrorBoundary`
on again." `react-error-boundary` supports this with a `resetErrorBoundary`
function it passes to our `FallbackComponent`. We can use this to reset the
error boundary and try again.

Expand Down
5 changes: 4 additions & 1 deletion exercises/08.errors/03.problem.reset/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ function ErrorFallback({ error }: FallbackProps) {
<div role="alert">
There was an error:{' '}
<pre style={{ color: 'red', whiteSpace: 'normal' }}>{error.message}</pre>
{/* 🐨 add a "Try again" button and pass the resetErrorBoundary function to the onClick prop */}
{/*
🐨 Add a "Try again" button. Assign the resetErrorBoundary function to its onClick prop.
πŸ’° For more on the onClick event handler, visit: πŸ“œ https://react.dev/learn/responding-to-events
*/}
</div>
)
}
Expand Down

0 comments on commit a781787

Please sign in to comment.