I registered a component to upload a file but it’s driving me crazy. According to what I understand from the documentation, I am doing everything right, but every time the onChange is triggered, the component re-renders infinitely, entering a loop, and I don’t understand why. My code looks like this:
Component
import { Upload, UploadFile } from "antd";
import ImgCrop from "antd-img-crop";
export interface CropperProps {
content : JSX.Element;
onChange : (file : UploadFile) => void;
};
export default function Cropper({
content,
onChange,
} : CropperProps) {
return (
<ImgCrop
showGrid
showReset
rotationSlider
cropShape="round"
modalOk="Recortar"
modalCancel="Cancelar"
resetText="Restablecer"
>
<Upload
accept="image/*"
multiple={false}
showUploadList={false}
onChange={ ({ file }) => {
onChange(file);
}}
>
{content}
</Upload>
</ImgCrop>
);
};
Registration
const CropperConfig : ExtendedCodeComponentMeta = {
id : "cropper",
name : "Cropper",
importPath : "~/components/Cropper/Cropper.tsx",
isDefaultExport : true,
displayName : "Cropper",
styleSections : true,
states : {
file : {
type : "writable",
variableType : "object",
valueProp : "value",
onChangeProp : "onChange",
},
},
props : {
value : {
type : "object",
displayName : "Value",
advanced : true,
},
onChange : {
type : "eventHandler",
displayName : "On Change",
argTypes : [
{
name : "file",
type : "object",
},
],
advanced : true,
},
content : {
type : "slot",
displayName : "Content",
defaultValue : [
{
type : "text",
value : "Cropper",
},
],
},
}
};```