commit 02376ac97fbdd794cc487dd6d1131fb8c925c890
parent 335543d369de2190a8a0591553117ea525ba1380
Author: Adrián Oliva <[email protected]>
Date:   Wed, 17 May 2023 22:18:32 -0600

Displayed correct index.

Index was hard-coded. Now it retrieves current last index used.

Diffstat:
Msrc/ToDo.jsx | 9+++++++--
Msrc/features/todo/reducer.js | 1+
2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/ToDo.jsx b/src/ToDo.jsx @@ -1,9 +1,14 @@ import React, { useState } from "react"; import { useSelector, useDispatch } from "react-redux"; -import { add_todo, select_todos } from "./features/todo/reducer"; +import { + add_todo, + select_todos, + select_last_index, +} from "./features/todo/reducer"; export function NewToDo() { const my_todos = useSelector(select_todos); + const my_last_idx = useSelector(select_last_index); const dispatch = useDispatch(); const [new_text, set_new_text] = useState(""); @@ -68,7 +73,7 @@ export function NewToDo() { <input className="form-control" id="new-todo-id" - value="4" + value={my_last_idx + 1} disabled /> <label htmlFor="floatingInput">ID</label> diff --git a/src/features/todo/reducer.js b/src/features/todo/reducer.js @@ -28,5 +28,6 @@ export const todo_slice = createSlice({ export const { add_todo } = todo_slice.actions; export const select_todos = (state) => state.todo_list.todos; +export const select_last_index = (state) => state.todo_list.last_id; export default todo_slice.reducer;