类型错误:无法在调度中设置未定义的属性(设置“表单”)

问题描述 投票:0回答:1

我有一个图像拖放输入字段。当图像被放下时,它会调用

handleIconDrop
函数。我正在打电话给我的调度员邮寄到我们的 BE。我的问题是这样做时出现此错误。

这是输入:

<ReactField
  adminStyle={true}
  component="bs-input"
  name="icon80x80FileName"
  label={`${client.name} Icon`}
  placeholder="Drag & Drop Image Here"
  value="Drag & Drop Image Here"
  onDrop={(e) => { handleIconDrop(e, manifestType); }}
/>

这是handleIconDrop函数:

const handleIconDrop = async ( event: React.DragEvent<HTMLInputElement>, manifestType: string) => {
    event.preventDefault();
    const file = event.dataTransfer.files[0];
    try {
        await saveManifestIcon({
          headers: { clientId: client.id, 'Content-Type': 'multipart/form-data' },
          manifestType: manifestType,
          form: file,
        });
    } catch (e) {
      console.error(msg.load.error, e);
      if (e.response?.status === 406 || e.response?.status === 404) {
        setInfo(msg.load.notFound);
      }
      else {
        setInfo(msg.load.error);
      }
    }
  };

这是调度:

const mapDispatchToProps = (dispatch) => ({
  actions: bindActionCreators(
    {
      saveManifestIcon: assetAdminApiActions.createAdminOfficeManifestsByManifestTypeIcons,
    },
    dispatch
  )
});

interface StateProps {
  client: ClientModel;
}
interface DispatchProps {
  actions: {
    saveManifestIcon: typeof assetAdminApiActions.createAdminOfficeManifestsByManifestTypeIcons,
  }
}

这是 API 调用本身的 dist 构建:

createAdminOfficeManifestsByManifestTypeIcons: ({ manifestType, form, data, }: {
  manifestType: string;
  form: object;
  data?: any;
}, options?: object) => Promise<any>;

有人可以告诉我我是否缺少初始化或其他东西吗?我已经在这个问题上坚持太久了。

提前非常感谢!

我尝试初始化“form”并尝试放置 if(form) 条件,但似乎没有任何效果:(

reactjs typescript redux dispatch
1个回答
0
投票

感觉这是一个显而易见的问题。你确定

const file = event.dataTransfer.files[0]
不是
undefined
吗?

© www.soinside.com 2019 - 2024. All rights reserved.