02_lesson: Add canSave check function to disable Save Post button

02_lesson
Jason Zhu 2023-03-07 13:33:38 +11:00
parent 00fcac1145
commit 75f98755b7
1 changed files with 3 additions and 1 deletions

View File

@ -25,6 +25,8 @@ const AddPostForm = () => {
}
};
const canSave = Boolean(title) && Boolean(content) && Boolean(userId);
const usersOptions = users.map((user) => (
<option key={user.id} value={user.id}>
{user.name}
@ -55,7 +57,7 @@ const AddPostForm = () => {
value={content}
onChange={onContentChanged}
/>
<button type="button" onClick={onSavePostClicked}>
<button type="button" onClick={onSavePostClicked} disabled={!canSave}>
Save Post
</button>
</form>