Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/content/learn/managing-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function Form() {
const [answer, setAnswer] = useState('');
const [error, setError] = useState(null);
const [status, setStatus] = useState('typing');
const showError = status === 'typing' && error && answer === error.failedAnswer;

if (status === 'success') {
return <h1>That's right!</h1>
Expand All @@ -49,6 +50,7 @@ export default function Form() {
} catch (err) {
setStatus('typing');
setError(err);
setError({ message: err.message, failedAnswer: answer });
}
}

Expand All @@ -75,7 +77,7 @@ export default function Form() {
}>
Submit
</button>
{error !== null &&
{showError &&
<p className="Error">
{error.message}
</p>
Expand Down
6 changes: 4 additions & 2 deletions src/content/learn/reacting-to-input-with-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ async function handleFormSubmit(e) {
}

function handleTextareaChange() {
hide(errorMessage);
if (textarea.value.length === 0) {
disable(button);
} else {
Expand Down Expand Up @@ -414,6 +415,7 @@ export default function Form() {
const [answer, setAnswer] = useState('');
const [error, setError] = useState(null);
const [status, setStatus] = useState('typing');
const showError = status === 'typing' && error && answer === error.failedAnswer;

if (status === 'success') {
return <h1>That's right!</h1>
Expand All @@ -427,7 +429,7 @@ export default function Form() {
setStatus('success');
} catch (err) {
setStatus('typing');
setError(err);
setError({ message: err.message, failedAnswer: answer });
}
}

Expand All @@ -454,7 +456,7 @@ export default function Form() {
}>
Submit
</button>
{error !== null &&
{showError &&
<p className="Error">
{error.message}
</p>
Expand Down