Connected addTask component to store, fixed cursor position on autofocus of text fields

This commit is contained in:
2021-10-17 18:20:49 +03:00
parent 3edf5edaec
commit 0b730b8b2d
4 changed files with 32 additions and 7 deletions

View File

@@ -13,8 +13,14 @@ export const todoSlice = createSlice({
name: "todo",
initialState: initialState,
reducers: {
add: (state, { payload }: PayloadAction<TaskItemT>) => {
state.tasks.push(payload);
add: (state, { payload }: PayloadAction<string>) => {
const newId = state.tasks[state.tasks.length - 1]?.id ?? 0;
state.tasks.push({
done: false,
text: payload,
id: newId,
});
},
updateText: (
state,