【发布时间】:2021-08-24 01:27:32
【问题描述】:
我正在尝试从该州访问联系人,但我总是获得整个州。
我尝试过解构,但这也不起作用?
我的切片包含工具包和 thunk。
export interface Contact {
name: string;
phone: string;
id: number;
}
export interface contactSliceState {
contacts: Contact[];
status: "idle" | "pending" | "succeeded" | "failed";
loading: boolean;
}
const contacts: Contact[] = useSelector<contactSliceState, Contact[]>(
(state) => state.contacts
);
console.log("contacts", contacts)
contacts:
0: {name: "John", phone: "123012", id: 1}
1: {name: "Bill", phone: "653722", id: 2}
2: {name: "Tom", phone: "874932", id: 3}
loading: false
status: "succeeded"
【问题讨论】:
-
contacts不是数组吗? -
在 useSelector 函数中执行
console.log(state)来检查状态的真实形状,因为这里没有加起来
标签: reactjs typescript redux redux-thunk