Skip to content

Instantly share code, notes, and snippets.

@greaveselliott
Last active June 23, 2019 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greaveselliott/f1497e67b6350ea15ea0b56e5836b838 to your computer and use it in GitHub Desktop.
Save greaveselliott/f1497e67b6350ea15ea0b56e5836b838 to your computer and use it in GitHub Desktop.
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>)
const onDeleteListItem = uuid => {
deleteNewListItem({
dispatch,
payload: {
uuid
}
});
};
const onFormSubmit = event => {
event.preventDefault();
createNewListItem({
dispatch,
payload: { listItemValue: input.current.value }
});
};
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