在React的一个演示项目中工作时,我希望按钮的功能在移动视图和桌面视图中的工作方式不同。所以我只想知道最好的方法是什么..谢谢...
Try react-responsive package . Show the difference button based on Different view port
React-responsive library reference
import MediaQuery from 'react-responsive';
const Example = () => (
<div>
<div>Device Test!</div>
<div>You are a desktop or laptop</div>
<MediaQuery query="(min-device-width: 1824px)">
<div>You also have a huge screen</div>
<Button onClick={handleMethod()} />
</MediaQuery>
<MediaQuery query="(max-width: 1224px)">
<Button onClick={handleAnotherMethod()} />
</MediaQuery>
</div>
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.