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) => ( const usersOptions = users.map((user) => (
<option key={user.id} value={user.id}> <option key={user.id} value={user.id}>
{user.name} {user.name}
@ -55,7 +57,7 @@ const AddPostForm = () => {
value={content} value={content}
onChange={onContentChanged} onChange={onContentChanged}
/> />
<button type="button" onClick={onSavePostClicked}> <button type="button" onClick={onSavePostClicked} disabled={!canSave}>
Save Post Save Post
</button> </button>
</form> </form>