我正在用 reactjs 撰寫一個應用程式
我想上傳作為道具從子組件傳遞到父組件的檔案
子組件
const RegisterIndividual: React.FC< { upload_id_card: React.ChangeEventHandler<HTMLInputElement>} > = ({
upload_id_card,
handleInput }) => {
return (
<div className="mt-3">
<input
type="file"
name="profile_picture"
id=""
onChange=={upload_id_card}
style={{ display: "block", marginTop: "1rem" }}
/>
</div>
)};
父組件
const Register = () => {
const upload_id_card = (event) => {
console.log("type upload file code here")
}
return (
<div className="__register">
<RegisterIndividual upload_id_card={upload_id_card} />
</div>
)}
但我在子組件上收到此錯誤
Type 'true' is not assignable to type 'ChangeEventHandler<HTMLInputElement> | undefined'.ts(2322)
uj5u.com熱心網友回復:
洗掉==并替換為=,您要分配而不是比較:
onChange=={upload_id_card}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/411655.html
標籤:
