You can choose the cols
value depending on the width (xs, sm, md, lg, xl
), look at this example where 1 column is set for smaller screens.
import React from "react";
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import compose from 'recompose/compose';
// @material-ui/core components
import withStyles from "@material-ui/core/styles/withStyles";
import withWidth from '@material-ui/core/withWidth';
import GridList from '@material-ui/core/GridList';
import GridListTile from '@material-ui/core/GridListTile';
import GridListTileBar from '@material-ui/core/GridListTileBar';
const styles = theme => ({ });
class MyComponent extends React.Component {
render() {
const { classes, currentUser, images, width } = this.props;
let columns = width === 'xs' || width === 'sm' ? 1 : 2;
return (
<div className={classes.root}>
<GridList cellHeight={180} cols={columns} className={classes.gridList}>
{images.map(image => (
<GridListTile key={image.id}>
<img src={ image.path } />
<GridListTileBar
title={ image.name }
/>
</GridListTile>
))}
</GridList>
</div>
);
}
}
MyComponent.propTypes = {
currentUser: PropTypes.object,
images: PropTypes.array.isRequired
};
function mapStateToProps(state) {
return {
currentUser: state.user.currentUser
};
}
export default compose(
withStyles(styles, {
name: 'MyComponent',
}),
withWidth(),
connect(mapStateToProps),
)(MyComponent);