7 Using Material-UI in React-JS

src/First.tsx: 
 
import React, { Component } from "react";
import Second from "./Second";

interface IState {
  key1: string;
  key2: number;
  key3: any[];
}

interface IProps {}

class First extends Component<IProps, IState> {
  constructor(props: IProps) {
    super(props);
    this.state = {
      key1: "Atharva Agrawal",
      key2: 1,
      key3: [
        {
          name: "Shirt",
          price: 100,
          rating: 2.5,
          image:
            "https://pisco.meaww.com/6ec1615c-5a8d-45ab-b7e1-04e1ad228f7d.634818810",
        },
        {
          name: "Polo Shirt",
          price: 200,
          rating: 2.5,
          image:
            "https://pisco.meaww.com/6ec1615c-5a8d-45ab-b7e1-04e1ad228f7d.634818810",
        },
      ],
    };
  }

  render() {
    return (
      <React.Fragment>
        <Second
          key1={this.state.key1}
          key2={this.state.key2}
          key3={this.state.key3}
        >
          {" "}
          {"ReactJS with TypeScript"}{" "}
        </Second>
      </React.Fragment>
    );
  }
}

export default First;


src/Second.tsx: 
 
import React, { Component } from "react";
import Third from "./Third";

interface IState {}

interface IProps {
  key1: string;
  key2: number;
  key3: any[];
}

class Second extends Component<IProps, IState> {
  constructor(props: IProps) {
    super(props);
  }

  render() {
    return (
      <React.Fragment>
        <Third
          key1={this.props.key1}
          key2={this.props.key2}
          key3={this.props.key3}
          key4={this.props.children}
        ></Third>
      </React.Fragment>
    );
  }
}

export default Second;


src/Third.tsx: 
 import React, { Component } from "react";

import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableContainer from "@material-ui/core/TableContainer";
import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
import Paper from "@material-ui/core/Paper";
import { makeStyles } from "@material-ui/core/styles";
import { Avatar } from "@material-ui/core";
interface IState {}

interface IProps {
  key1: string;
  key2: number;
  key3: any[];
  key4: any;
}

class Third extends Component<IProps, IState> {
  constructor(props: IProps) {
    super(props);
  }

  render() {
    return (
      <React.Fragment>
        <h1> {this.props.key1} </h1>
        <h2> {this.props.key2} </h2>
        <h2> {this.props.key4} </h2>
        <TableContainer component={Paper} style={{ width: "50%" }}>
          <Table>
            <TableHead>
              <TableRow>
                <TableCell align="right">SNO</TableCell>
                <TableCell align="right">NAME</TableCell>
                <TableCell align="right">PRICE</TableCell>
                <TableCell align="right">RATING</TableCell>
                <TableCell align="right">IMAGE</TableCell>
              </TableRow>
            </TableHead>
            <TableBody>
              {this.props.key3.map((element, index) => (
                <TableRow key={index}>
                  <TableCell align="right"> {index + 1} </TableCell>
                  <TableCell align="right"> {element.name} </TableCell>
                  <TableCell align="right"> {element.price} </TableCell>
                  <TableCell align="right"> {element.rating} </TableCell>
                  <TableCell>
                    <Avatar src={element.image} variant="rounded"></Avatar>
                  </TableCell>
                </TableRow>
              ))}
            </TableBody>
          </Table>
        </TableContainer>
      </React.Fragment>
    );
  }
}

export default Third;

public/index.html: 
 <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />

  <link rel="stylesheet" href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap' />
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />

  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="theme-color" content="#000000" />
  <meta name="description" content="Web site created using create-react-app" />
  <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
  <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
  <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
  <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
  <title>React App</title>
</head>

<body>
  <noscript>You need to enable JavaScript to run this app.</noscript>
  <div id="root"></div>
  <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
</body>

</html>
Output: 
reactjs using materialui

Previous
Next Post »