import { createSlice } from '@reduxjs/toolkit';
import { useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { StateType } from './redux-store';
const initialState = {
list: [] as { id: number }[],
title: '',
};
const todoReducer = createSlice({
name: 'todo',
initialState,
reducers: {
_addTodo: (state, action) => {
state.list.unshift(action.payload);
},
_setTitle: (state, action) => {
state.title = action.payload;
},
},
});
const { reducer, actions } = todoReducer;
interface Return {
list: { id: number }[];
title: string;
addTodo: (data: string) => void;
setTitle: (title: string) => void;
}
const useTodo = (): Return => {