I would like to pass down a link to a component that is going to be rendered on the same page. I have a Navbar that has links and I want to set the href to '.Container-One'
that's referenced in another component. How should I do this if I'm using React Hooks functional components?
Here is my Navbar.js
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";
const useStyles = makeStyles(theme => ({
root: {
flexGrow: 1
},
menuButton: {
marginRight: theme.spacing(2)
},
title: {
flexGrow: 1
}
}));
export default function ButtonAppBar() {
const classes = useStyles();
return (
<div className={classes.root}>
<AppBar style={{ backgroundColor: "#343567" }} position="static">
<Toolbar>
<Typography variant="h6" className={classes.title}>
Welcome
</Typography>
<Button
onClick={e => e.preventDefault()}
href={".Container-One"}
color="inherit"
>
About
</Button>
<Button color="inherit">Experience</Button>
<Button color="inherit">Contact</Button>
</Toolbar>
</AppBar>
</div>
);
}
Here is my component that I would like it to be linked too.
import React from "react";
import CssBaseline from "@material-ui/core/CssBaseline";
import Typography from "@material-ui/core/Typography";
import Container from "@material-ui/core/Container";
import styles from "./aboutme.module.css";
import myPhoto from "../../images/me.jpg";
import TrendingUpIcon from "@material-ui/icons/TrendingUp";
function AboutMe() {
return (
<div>
<Container className={styles["Container-One"]}>
<Typography className={styles["Content-One"]} component="div">
<h3 className={styles["Container-One-Heading"]}>
Hello! I'm lorem ipsum. Dont know me? Check me out at call lorem-
ipsum
</h3>
</Typography>
</Container>
</div>
);
}
export default AboutMe;
An example of this might be in simple HTML you would pass a button with href to a container or another HTML class or id on the same page.
For example:
<button href="#Container-Three"}>container-three section</button>
I would like to do this in react, but I'm using different components.