我是歌谣 微信公众号关注前端小歌谣 export const UserCreate = (props) = { const transform = (data) = { const sanitizedData = {}; for (const key in data) { if (typeof data[key] === "string" data[key].length === 0) continue; san
我是歌谣 微信公众号关注前端小歌谣
export const UserCreate = (props) => {
const transform = (data) => {
const sanitizedData = {};
for (const key in data) {
if (typeof data[key] === "string" && data[key].length === 0) continue;
sanitizedData[key] = data[key];
}
return sanitizedData;
};
return (
<Create {...props} transform={transform}>
...
</Create>
);
}
运行结果
文本输入的空值是空字符串,而不是null和undefined