【发布时间】:2022-01-15 23:46:52
【问题描述】:
我有当前状态:
const [newInvoice, setInvoice] = useState<InvoiceType | null>(invoice)
InvoiceType 我的类型是:
customer_email: string
customer_name: string
description: string
due_date: string
status: FilterButtonState
total: number
line_items: LineItemType[]
我正在尝试使用如下输入字段修改表单中的状态以修改以前的状态:
<input
...otherAttributes
onChange={(ev: React.ChangeEvent<HTMLInputElement>): void =>
setInvoice((prevState) => ({
...prevState,
customer_name: ev.target.value
}))
/>
但我不断收到以下类型错误:Argument of type '(prevState: InvoiceType | null) => { customer_name: string; customer_email?: string | undefined; description?: string | undefined; due_date?: string | undefined; status?: FilterButtonState | undefined; total?: number | undefined; line_items?: LineItemType[] | undefined; }' is not assignable to parameter of type 'SetStateAction<InvoiceType | null>'
我不确定如何构建它以便解决这个问题。感谢您的帮助。
【问题讨论】:
-
吹毛求疵:
InvoiceType是多余的 ->Invoice。
标签: javascript reactjs typescript