Browser is not showing me Output - reactjs

It's not showing slider and even the png that I have on the folder
please help as it very important m building my portfolio website
import React from "react";
import MenuIcon from "#material-ui/icons/Menu";
import { makeStyles } from "#material-ui/core/styles";
import {
AppBar,
Toolbar,
ListItem,
IconButton,
ListItemText,
Divider,
Avatar,
List,
Typography,
Box,
} from "#material-ui/core";
import {
ArrowBack,
AssignmentInd,
Home,
Apps,
ContactMail,
} from "#material-ui/icons";
import avatar from "../images/ava.png";
// CSS styles
const useStyles = makeStyles({
menuSliderContainer: {
width: 250,
background: "#000000",
height: "30rem",
},
});
const Navbar = () => {
const classes = useStyles;
return (
<>
<Box className={classes.menuSliderContainer} component="div">
<Avatar src={avatar} alt="Cyril Lawrence" />
</Box>
<Box component="nav">
<AppBar style={{ background: "#000000" }}>
<Toolbar>
<IconButton>
<MenuIcon style={{ color: "White" }} />
</IconButton>
<Typography variant="h6" style={{ padding: "0px 0px 0px 10px" }}>
Home
</Typography>
</Toolbar>
</AppBar>
</Box>
</>
);
};
export default Navbar;

Are you sure your path to your image is correct? I would also change all of your material ui imports to be like your MenuIcon import. It is best practice to import your MUI components this way to reduce bundle size. Example import Appbar from '#material-ui/core/Appbar'; This is because when you import like import { Button, TextField } from '#material-ui/core'; you are importing the entire MUI library, even though you are only using a few components. As your application grows you may start to notice load times starting to drag. You may read more about bundle size in the official documentation here https://material-ui.com/guides/minimizing-bundle-size/ You are also not initializing your useStyles function. Change to const classes = useStyles();

Related

App Bar not filling the top of the page MUI MATERIAL

I am using MUI MATERIAL.
I got an
It has a padding on the top,right,left of the page.
I want the App Bar to be at the very top of the page.
I tried using classes but it does not work.
components/AppBar/index.js
import * as React from "react";
import AppBar from "#mui/material/AppBar";
import Box from "#mui/material/Box";
import Toolbar from "#mui/material/Toolbar";
import Typography from "#mui/material/Typography";
import Button from "#mui/material/Button";
import IconButton from "#mui/material/IconButton";
import MenuIcon from "#mui/icons-material/Menu";
import { makeStyles } from "#mui/styles";
const useStyles = makeStyles({
root: {
backgroundColor: "#130f40",
margin: 0
}
});
export default function ButtonAppBar() {
const classes = useStyles();
return (
<Box sx={{ flexGrow: 1 }}>
<AppBar position="static" className={classes.root}>
<Toolbar>
<IconButton
size="large"
edge="start"
color="inherit"
aria-label="menu"
sx={{ mr: 2 }}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
News
</Typography>
<Button color="inherit">Login</Button>
</Toolbar>
</AppBar>
</Box>
);
}
You can add CssBaseline at the top level of your app to get rid of the space around the AppBar component. It will apply style rules from normalize.css which includes margin:0 on the body element which is the reason for this gap.
import * as React from 'react';
import CssBaseline from '#mui/material/CssBaseline';
export default function MyApp() {
return (
<React.Fragment>
<CssBaseline />
{/* The rest of your application */}
</React.Fragment>
);
}

Material-UI v5: makeStyles's not being imported

When I am trying to import "makeStyles" using :
import { makeStyles } from '#mui/styles';
it's not working. The page becomes blank when I run.
But It's working when I change the code and use V4:
import { makeStyles } from "#material-ui/core/styles";
I've installed alll the dependencies that is required. Why It's not working using V5 of material-ui?
Here is my code (styles.js):
import { makeStyles } from "#mui/material";
export default makeStyles((theme) => ({
title: {
display: "none",
[theme.breakpoints.up("sm")]: {
display: "block",
},
},
}));
Header.jsx:
import React from "react";
import { AppBar, Toolbar, Typography, InputBase, Box } from "#mui/material";
import SearchIcon from "#mui/icons-material/Search";
import useStyles from "./styles";
const Header = () => {
const classes = useStyles();
return (
<AppBar position="static">
<Toolbar>
<Typography variant="h5" className={classes.title}>
Travel Advsior
</Typography>
<Box display="flex">
<Typography variant="h6" className={classes.title}>
Explore new places
</Typography>
<div>
<div>
<SearchIcon />
</div>
<InputBase placeholder="Search..." />
</div>
</Box>
</Toolbar>
</AppBar>
);
};
export default Header;

Material UI invalid hook call

I am using the following template for a blog. But I want to try out Material UI. But when I add the useStyles-Hook I get an invalid hook error. Does anyone know how to implement Material UI without getting an error. Thank you in advance!
This is the error message:
Unhandled Runtime Error
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
You might have mismatching versions of React and the renderer (such as React DOM)
You might be breaking the Rules of Hooks
You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
import React from "react";
import { makeStyles } from "#material-ui/core/styles";
import AppBar from "#material-ui/core/AppBar";
import Toolbar from "#material-ui/core/Toolbar";
import Typography from "#material-ui/core/Typography";
import Button from "#material-ui/core/Button";
import IconButton from "#material-ui/core/IconButton";
import MenuIcon from "#material-ui/icons/Menu";
const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
},
menuButton: {
marginRight: theme.spacing(2),
},
title: {
flexGrow: 1,
},
}));
export default function Navigation({ categories }) {
const classes = useStyles();
return (
<div>
<div className={classes.root}>
<AppBar position="static">
<Toolbar>
<IconButton
edge="start"
className={classes.menuButton}
color="inherit"
aria-label="menu"
>
<MenuIcon />
</IconButton>
<Typography variant="h6" className={classes.title}>
News
</Typography>
<Button color="inherit">Login</Button>
</Toolbar>
</AppBar>
</div>
);
}
Your sample doesn't contains the MaterialUI parts.
did you try:
import React from 'react';
import { makeStyles } from '#material-ui/core/styles';
import Button from '#material-ui/core/Button';
const useStyles = makeStyles({
root: {
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
},
});
export default function Hook() {
const classes = useStyles();
return <Button className={classes.root}>Hook</Button>;
}
https://material-ui.com/styles/basics/

OnClick for material UI components is not working in React Js

I am using Material UI components in my project. OnClick is not working for button. I have search on google also but didn't find any solution. I have tried using div also but that is also not working.
import React from 'react';
import { makeStyles } from '#material-ui/core/styles';
import AppBar from '#material-ui/core/AppBar';
import Toolbar from '#material-ui/core/Toolbar';
import Typography from '#material-ui/core/Typography';
import MobileDrawer from "./MobileDrawer";
import MenuIcon from '#material-ui/icons/Menu';
import IconButton from "#material-ui/core/IconButton";
const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
},
menuButton: {
marginRight: theme.spacing(2),
},
title: {
flexGrow: 1,
marginLeft: "20px",
marginTop: "8px"
},
}));
export default function MobileHeader() {
const classes = useStyles();
const handleDrawerStatus = () => {
alert("hi")
}
return (
<div className={classes.root}>
<AppBar position="static" style={{ backgroundColor: "#040b2d" }}>
<Toolbar>
<IconButton
color="inherit"
aria-label="open drawer"
edge="start"
onClick={handleDrawerStatus}
>
<MenuIcon />
</IconButton>
</Toolbar>
</AppBar>
</div>
);
}

Material-UI not applying color theme to a button as it should be

I'm trying to follow this documentation. I am trying to get Login button to turn green, but it seems to not inherit any theme styling with the given code. Not sure what I'm doing wrong.
I have the following code:
import React from "react";
import {
createMuiTheme,
withStyles,
makeStyles
} from "#material-ui/core/styles";
import { ThemeProvider } from "#material-ui/styles";
import green from "#material-ui/core/colors/green";
import AppBar from "#material-ui/core/AppBar";
import Toolbar from "#material-ui/core/Toolbar";
import Typography from "#material-ui/core/Typography";
import Button from "#material-ui/core/Button";
import IconButton from "#material-ui/core/IconButton";
import MenuIcon from "#material-ui/icons/Menu";
import { Link } from "react-router-dom";
const useStyles = makeStyles(theme => ({
root: {
flexGrow: 1
},
menuButton: {
marginRight: theme.spacing(2)
},
title: {
flexGrow: 1
}
}));
const theme = createMuiTheme({
palette: {
primary: green
}
});
export default function ButtonAppBar() {
const classes = useStyles();
return (
<div className={classes.root}>
<AppBar position="static">
<Toolbar>
<IconButton
edge="start"
className={classes.menuButton}
color="inherit"
aria-label="Menu"
>
<MenuIcon />
</IconButton>
<Typography variant="h6" className={classes.title}>
Hello
</Typography>
<ThemeProvider theme={theme}>
<Link to="/login">
<Button color="secondary">Login</Button>
</Link>
</ThemeProvider>
</Toolbar>
</AppBar>
</div>
);
}
If I were to paste in all the code from the documentation, then I would see the three buttons of each color. But my variation of the code doesn't work.
I am assuming you mean this button?
<Link to="/login">
<Button color="secondary">Login</Button>
</Link>
if so you need to set it to Primary not secondary. You need it wrapped in themeProvider too. If you look at the custom code in that doc you posted you should see this
<ThemeProvider theme={theme}>
<Button variant="contained" color="primary" className={classes.margin}>
Theme Provider
</Button>
</ThemeProvider>
It should match what you use in the createMuiTheme:
const theme = createMuiTheme({
palette: {
primary: green
}
});
You are putting the Button's color="secondary". While creating the palette, you are defining the color green for the primary attribute. I tried it in this sandbox to change the Button's color prop to color="primary" and it changes to green.

Resources