React中如何将isMobile变量传入Drawer组件的size="full"属性
解决方案
你可以通过动态绑定size属性,根据isMobile的值来控制Drawer的显示尺寸:
const isMobile = useMediaQuery('(max-width:992px)'); // 根据移动端状态切换Drawer尺寸 <Drawer size={isMobile ? 'full' : 'md'}> {/* Drawer内部内容 */} </Drawer>
补充说明
- 当
isMobile为true(屏幕宽度≤992px)时,Drawer会启用size="full"实现全屏; - 非移动端场景下,你可以把
'md'替换为Rsuite支持的其他尺寸值,比如'lg'(大尺寸)、'sm'(小尺寸),或者保留组件默认的尺寸逻辑。
内容的提问来源于stack exchange,提问作者Asha Saini
相关产品推荐
相关产品推荐

