我無法弄清楚如何將道具傳遞給 Box 組件覆寫。
我需要按照 InputAdornment 的要求傳遞 position="end"",但在檔案中找不到方法。
完整的組件是
<Select
value={value}
onChange={handleChange}
input={
<OutlinedInput
endAdornment={
photoRequired && (
<Box component={InputAdornment} position="end" pr={3}>
{required && <Gallery />}
<Gallery />
</Box>
)
}
/>
}
>
{choices.map((choice, i) => (
<MenuItem key={i} value={i 1}>
{choice}
</MenuItem>
))}
</Select>
我在嘗試以上述方式傳遞時遇到錯誤,因為它在 Box 上不符合預期。
Warning: Failed prop type: The prop `position` is marked as required in `ForwardRef(InputAdornment)`, but its value is `undefined`.```
uj5u.com熱心網友回復:
嘗試創建自己的InputAdornment使用位置的組件,例如:
const EndInputAdornment = () => {
return <InputAdornment position="end"/>
};
然后您可以將該組件用于Box:
<Box component={EndInputAdornment} pr={3}>
...
或者如果您不想創建單獨的組件:
<Box component={<InputAdornment position="end"/>} pr={3}>
應該管用
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/392713.html
上一篇:尋找更好的方式來構建代碼
