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> ); };