I am using react-redux with typescript. I am importing a JSON file in my redux slice for an initial value. Now, I want to perform a crud operation on a dictionary. I want to add item only in the required key, for that what will be the type structure and how do I perform the operation?
my external JSON contains employee data with respect to the department. department as a key and employees as an array of objects. my structure looks like below:
{
"0": [{...},{...},{...}],
"1": [{...},{...},{...}],
"2": [{...},{...},{...}],
}
My slice code looks like this:
type employeeType = {
id: number,
name: string,
age: number,
DOB: number
}
type departments = {
[departmentNo: string]: employeeType[];
}
const initialState:departments = require("./data.json");
export const employeeReducer = (state: departments = initialState, action: any) => {
switch (action.type){
case "ADD_EMPLOYEE": {
return ({})
}
default: {
return state
}
}
}