vendredi 29 novembre 2019

React and MaterialUI - GridLayout using papers

I'm using react-grid-layout library to create an adapting grid which each item is a paper component from react material ui.

I'm having a problem when running the application I receive in the broswer: "TypeError: react__WEBPACK_IMPORTED_MODULE_0___default.a.createContext is not a function" Under the module of "./node_modules/@material-ui/styles/esm/useTheme/ThemeContext.js"

I'm pretty new to react and all so maybe I've done something very stupid but help will be much appreciated because I'm kind of clueless :)

The Home component is:

import { makeStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import { withStyles } from '@material-ui/styles';
import { Paper } from 'material-ui';
import React from 'react';
import GridLayout from 'react-grid-layout';

const useStyles = makeStyles(theme => ({
    root: {
        padding: theme.spacing(3,2),
    },
}));

class Home extends React.Component {


    render() {
        var layout = [
            {i: 'a', x: 0, y: 0, w: 1, h: 2, static: true},
            {i: 'b', x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4},
            {i: 'c', x: 4, y: 0, w: 1, h: 2}
        ];

        const { classes } = this.props;

        return (
            <GridLayout className="layout" layout={layout} cols={12} rowHeight={30} width={1200}>
                <Paper className={classes.root}>
                    <Typography key="a" variant="h5" component="h3">
                        This is a set of paper!
                    </Typography>
                </Paper>
                <Paper className={classes.root}>
                    <Typography key="b" variant="h5" component="h3">
                        This is a set of paper!
                    </Typography>
                </Paper>
                <Paper className={classes.root}>
                    <Typography key="c" variant="h5" component="h3">
                        This is a set of paper! 
                    </Typography>
                </Paper>
            </GridLayout>
        );
    }


    /* 
    <MapContainer latitude={31.97973975} longitude={34.74769792490634}/>
    */
}

export default withStyles(useStyles)(Home);

This is the App.js file:

import { MuiThemeProvider } from 'material-ui/styles';
import React from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import './App.css';
import Home from './pages/Home';

class App extends React.Component {

    render() {
        return (
            <MuiThemeProvider>
                <Router>
                    <Route path="/" component={Home}/>
                </Router>
            </MuiThemeProvider>
        );
    }
}

export default App;

Thank you heads up!




Aucun commentaire:

Enregistrer un commentaire