Last active
June 23, 2019 01:58
-
-
Save greaveselliott/f1497e67b6350ea15ea0b56e5836b838 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return (<main className="app"> | |
<h1 className="app__title">To do list</h1> | |
<form className="app__form" onSubmit={onFormSubmit}> | |
<input type="text" className="app__input" ref={input} /> | |
<input | |
type="submit" | |
className="app__input-submit" | |
value="Add to list" | |
/> | |
</form> | |
<ul className="app__list"> | |
{state.list.map((listItem, index) => ( | |
<li className="app__list-item" key={`list-item-${index}`}> | |
{listItem.listItemValue} | |
<button | |
className="app__list-item-delete" | |
onClick={() => onDeleteListItem(listItem.uuid)} | |
> | |
Delete | |
</button> | |
</li> | |
))} | |
</ul> | |
</main>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const onDeleteListItem = uuid => { | |
deleteNewListItem({ | |
dispatch, | |
payload: { | |
uuid | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const onFormSubmit = event => { | |
event.preventDefault(); | |
createNewListItem({ | |
dispatch, | |
payload: { listItemValue: input.current.value } | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useRef } from "react"; | |
const input = useRef(); | |
<input type="text" className="app__input" ref={input} /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment