Skip to content

Commit

Permalink
fix(ui): fix Todo not listening to outside changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bsbodden committed Feb 23, 2021
1 parent 2f69117 commit a136e68
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/webapp/src/components/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import { KEY_RETURN, KEY_ESCAPE } from 'keycode-js';
import useOnClickOutside from "../hooks/use_on_click_outside";

const Todo = function (props) {
const { getTodo, updateTodo, deleteTodo } = useContext(TodosContext);
const { getTodo, updateTodo, deleteTodo, todos } = useContext(TodosContext);
const [todo, setTodo] = useState(getTodo(props.id));
const [editing, setEditing] = useState(false);
const [title, setTitle] = useState(todo.title);
const [titleBeforeEditing, setTitleBeforeEditing] = useState("");
const wrapperRef = useRef(null);

useEffect(() => {
setTodo(getTodo(props.id));
}, [todos]);

useEffect(() => {
if (editing) {
setTitleBeforeEditing(title);
Expand Down

0 comments on commit a136e68

Please sign in to comment.