My react app is not rendering and I don't know what I'm doing wrong, the page is just the background color. I'm able to build the app with no errors. And I'm importing all the files into App and App on index.js.
App.js:
import React from 'react';
import { useState } from 'react';
import Header from './components/Header';
import Nav from './components/Nav';
import About from './components/pages/About';
import Skills from './components/pages/Skills';
import Projects from './components/Projects';
import Resume from './components/pages/Resume';
import Contact from './components/pages/Contact';
import Footer from './components/Footer';
const App = () => {
const [currentPage, setCurrentPage] = useState('About');
const renderPage = () => {
if (currentPage === "About") {
return <About />;
}
if (currentPage === "Skills") {
return <Skills />;
}
if (currentPage === "Projects") {
return <Projects />;
}
if (currentPage === "Contact") {
return <Contact />;
}
return <Resume />;
};
const handlePageChange = (page) => setCurrentPage(page);
return (
<div>
<Nav currentPage={currentPage} handlePageChange={handlePageChange} />
<Header />
{renderPage()}
<Footer/>
</div>
);
}
export default App;
index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
ReactDOM.render(<App/>, document.querySelector("#root"))
index.css
* {
margin:0;
padding: 0;
border:0;
outline:0;
box-sizing: border-box;
list-style: none;
text-decoration: none;
}
:root {
--color-bg: #1f1f38;
--color-bg-v: #2c2c6c;
--color-pr: #4db5ff;
--color-pr-v:rgba(77,181,255,0.4);
--color-w:white;
--color-light: rgba(255,255,255,0.6);
--container-w-lg:75%;
--container-w-md:86%;
--container-w-sm: 90%;
--transition: all 400ms ease;
}
html {
scroll-behavior:smooth;
}
::-webkit-scrollbar {
display:none
}
body {
font-family: 'Poppins', sans-serif;
background: var(--color-bg);
color: var(--color-w);
line-height: 1.7;
}
.container {
width: var(--container-w-lg);
margin: 0 auto;
}
h1,
h2,
h3,
h4,
h5 {
font-weight: 500;
}
h1 {
font-size:2.5rem;
}
section {
margin-top: 8rem;
}
section > h2, section > h5 {
text-align: center;
color: var(--color-light)
}
section > h2 {
color: var(--color-pr);
margin-bottom: 3rem;;
}
.text-light {
color: var(--color-light);
}
a {
color: var(--color-pr);
transition: var(--transition);
}
a:hover {
color: var(--color-w);
}
.btn {
width: max-content;
display: inline-block;
color: var(--color-pr);
padding: 0.75rem 1.2rem;
border-radius:0.4rem;
cursor:pointer;
border: 1px solid var(--color-pr);
transition: var(--transition);
}
.btn:hover {
background: var(--color-w);
color: var(--color-bg);
border-color: transparent;
}
.btn-primary {
background: var(--color-pr);
color:var(--color-bg)
}
img{
display:block;
width: 100%;
object-fit: cover;
}
@media screen and (max-width: 1024px) {
.container {
width: var(--container-w-md);
}
section {
margin-top: 6rem;
}
}
@media screen and (max-width: 1024px) {
.container {
width: var(--container-w-sm);
}
section > h2{
margin-top: 2rem;
}
}
I tried rewrite the functions without using arrow functions, tried to rename the files, and tried to write the content from the App into another file and import to App, cause I read it could solve my problem. But nothing worked.
rootimport React from 'react'; import ReactDOM from 'react-dom/client'; import App from './App'; const root = ReactDOM.createRoot(document.getElementById('root')); root.render( <App /> );