Photo by Michael Browning on Unsplash

You May Not Need a Slider — At Least For Mobile Browsers

Bundle Size and Download Time of react-slick@0.25.2
Bundle Size and Download Time of react-slick@0.25.2
const Container = styled.div`
white-space: nowrap;
overflow-x: auto;
overflow-y: hidden;
padding-left: 18px;
padding-right: 18px;
padding-bottom: 18px;
margin-top: 0;
margin-left: -24px;
margin-right: -24px;
-webkit-overflow-scrolling: touch;
-ms-overflow-style: none;
scrollbar-width: none;
`;
const Slider = props => {
const { children, childWidth, ...rest } = props;
const Container = styled.div`
white-space: nowrap;
overflow-x: auto;
overflow-y: hidden;
padding-left: 18px;
padding-right: 18px;
padding-bottom: 18px;
margin-top: 0;
margin-left: -24px;
margin-right: -24px;
-webkit-overflow-scrolling: touch;
-ms-overflow-style: none;
scrollbar-width: none;


> * {
padding: 0 6px;
display: inline-block;
white-space: normal;
word-break: break-word;
vertical-align: top;
width:
${childWidth};
}
`;
return (
<Container {...rest}>
{children}
</Container>
);
};
import React from 'react';
import PropTypes from 'prop-types';
import styled from '@emotion/styled';
const Slider = props => {
const { children, childWidth, ...rest } = props;
const Container = styled.div`
white-space: nowrap;
overflow-x: auto;
overflow-y: hidden;
padding-left: 18px;
padding-right: 18px;
padding-bottom: 18px;
margin-top: 0;
margin-left: -24px;
margin-right: -24px;
-webkit-overflow-scrolling: touch;
-ms-overflow-style: none;
scrollbar-width: none;


> * {
padding: 0 6px;
display: inline-block;
white-space: normal;
word-break: break-word;
vertical-align: top;
width:
${childWidth};
}
`;
return (
<Container {...rest}>
{children}
</Container>
);
};
Slider.propTypes = {
children: PropTypes.any,
childWidth: PropTypes.string,
};
Slider.defaultProps = {
childWidth: ‘80%’,
};
export default Slider;

The result:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store