@ -49,7 +49,7 @@ async function handleFormSubmit(e) {
} catch (err) {
show(errorMessage);
errorMessage.textContent = err.message;
} finally {
} finally {
hide(loadingMessage);
enable(textarea);
enable(button);
@ -373,7 +373,7 @@ You want to avoid duplication in the state content so you're only tracking what
Here are some questions you can ask about your state variables:
* **Does this state cause a paradox?** For example, `isTyping` and `isSubmitting` can't both be `true`. A paradox usually means that the state is not constrained enough. There are four possible combinations of two booleans, but only three correspond to valid states. To remove the "impossible" state, you can combine these into a `status` that must be one of three values: `'typing'`, `'submitting'`, or `'success'`.
* **Does this state cause a paradox?** For example, `isTyping` and `isSubmitting` can't both be `true`. A paradox usually means that the state is not constrained enough. There are four possible combinations of two booleans, but only three correspond to valid states. To remove the "impossible" state, you can combine these into a `status` that must be one of three values: `'typing'`, `'submitting'`, or `'success'`.
* **Is the same information available in another state variable already?** Another paradox: `isEmpty` and `isTyping` can't be `true` at the same time. By making them separate state variables, you risk them going out of sync and causing bugs. Fortunately, you can remove `isEmpty` and instead check `answer.length === 0`.
* **Can you get the same information from the inverse of another state variable?**`isError` is not needed because you can check `error !== null` instead.
@ -572,7 +572,7 @@ export default function Picture() {
} else {
backgroundClassName += ' background--active';
}
return (
<div
className={backgroundClassName}
@ -702,14 +702,14 @@ Here is a small form implemented with plain JavaScript and DOM. Play with it to
```js index.js active
function handleFormSubmit(e) {
e.preventDefault();
if (button.textContent === 'Edit Profile') {
button.textContent = 'Save Profile';
if (editButton.textContent === 'Edit Profile') {
editButton.textContent = 'Save Profile';
hide(firstNameText);
hide(lastNameText);
show(firstNameInput);
show(lastNameInput);
} else {
button.textContent = 'Edit Profile';
editButton.textContent = 'Edit Profile';
hide(firstNameInput);
hide(lastNameInput);
show(firstNameText);
@ -744,11 +744,11 @@ function show(el) {
}
let form = document.getElementById('form');
let profile = document.getElementById('profile');
let editButton = document.getElementById('editButton');
let firstNameInput = document.getElementById('firstNameInput');
let firstNameText = document.getElementById('firstNameText');
let lastNameInput = document.getElementById('lastNameInput');
let lastNameText = document.getElementById('lastNameText');
let helloText = document.getElementById('helloText');