P粉5118967162023-09-02 12:25:33
您可以从rest
中提取出style
属性,然后删除其margin
属性(之前设置的),并用您自定义的marginBottom: 45
覆盖它。
const Input = ({ name, style, ...rest }) => { const { margin, ...restStyles } = style; const newStyles = { ...restStyles, marginBottom: 45, }; return ( <div> <input type="text" name={name} {...rest} style={newStyles} /> // ^^^^^^^^^ 应用新样式 {errors && <span>错误:请添加您的姓名</span>} </div> ); };