I have a trivial problem. Having this file structure, I'd like to expose all components (in index.js) so they are reachable in App.js, like that: import { Header, Menu } from "../components";. But I'm getting error that neither Home nor Menu are in the components. Here is the structure:
src/
index.js
app/
App.js
createStore.js
reducers.js
components/
index.js <--------------- In here, I'd like to export all components
button/
Button.js
Button.styles.js
header/
Header.js
Header.styles.js
modules/
foo/
bar/
This is Header:
import React from "react";
import { AppBar, Toolbar, Typography } from "@material-ui/core";
import useStyles from "./Header.styles";
const Header = () => {
const classes = useStyles();
return (
<AppBar position="fixed" className={classes.appBar}>
<Toolbar>
<Typography variant="h5">LineupFarm</Typography>
</Toolbar>
</AppBar>
);
};
export default Header;
This is components/index.js
import Header from "../components/Header/Header";
import Menu from "../components/Menu/Menu";
export default {
Header,
Menu,
};
... and this is my App.js:
import React from "react";
import { Route, Switch } from "react-router-dom";
import { ThemeProvider, CssBaseline, Toolbar } from "@material-ui/core";
import { Header, Menu } from "../components"; // <------------ Getting error: "Menu not found in '../components'" Why?
function App() {
const classes = useStyles();
return (
<div className={classes.root}>
<CssBaseline />
<Header />
<Menu />
<main className={classes.content}>
</main>
</div>
);
}
export default App;
Why am I getting error "Menu not found in '../components'"? What am I doing wrong?