我面临的问题是,我在feed.js和sidebar.jsx中所做的任何改变都没有反映在react网站上。然而,navbar.jsx的变化正在立即反映在网站上。即使完全停止并启动react应用程序也不能反映网站的变化。
在排除故障时,我最初认为错误源于React路由器,但在检查了其中的所有内容数小时后,我认为问题并不来自于此。
如果我不得不猜测的话,我认为问题就在文件的导入/导出中,但我不知道如何解决它。
任何帮助都将不胜感激,
App.js
import { BrowserRouter, Routes, Route } from "react-router-dom";
import { Box } from "@mui/material";
import Navbar from "./components/Navbar";
import Feed from "./components/Feed";
import VideoChannel from "./components/VideoChannel";
import VideoDetail from "./components/VideoDetail";
import SearchFeed from "./components/SearchFeed";
import Sidebar from "./components/Sidebar";
const App = () => (
<BrowserRouter>
<Box sx={{ backgroundColor: "#5c44ad" }}>
<Navbar />
<Routes>
<Route path="/ImportElement/:id" exact element = {<ImportElement />} />
<Route path="/Sidebar/:id" exact element={<Sidebar />} />
<Route path="/Feed/:" exact element={<Feed />} />
<Route path="/video/:id" exact element={<VideoDetail />} />
<Route path="/channel/:id" exact element={<VideoChannel />} />
<Route path="/search/:searchTerm" exact element={<SearchFeed />} />
</Routes>
</Box>
</BrowserRouter>
);
export default App;Sidebar.jsx
import {Stack} from '@mui/material'
import {categories} from '../utils/constant'
const selectedCategory='New';
const Sidebar = () => (
<Stack direction="row" sx={{overflowY:"auto",
height:{sx:'auto',md:'95%'},
flexDirection:{md:'column'},
}}>
{categories.map((category)=>(
<button className='category-btn'
style={{
background:category.name===selectedCategory&& '#5c44ad',
color:'green'
}}
key={category.name}>
<span>{category.icon}</span>
<span>{category.name}</span>
</button>
))}
</Stack>
)
export default SidebarNavbar.jsx
import { Stack } from "@mui/material";
import { Link } from "react-router-dom";
import { logo } from "../utils/constant";
import SearchBar from './SearchBar';
const Navbar = () => (
<Stack
direction="row"
alignItems="center"
p={2}
sx={{
position: "sticky",
background: "#000",
top: 0,
justifyContent: "space-around",
}}
>
<Link to="/" style={{display:'flex',alignItems:'center'}}>
<img src={logo} alt="logo" height={45}/>
</Link>
<SearchBar/>
</Stack>
);
export default Navbar;Feed.js
//import { useState, useEffect } from "react";
import React from 'react';
import { Box, Stack, Typography } from "@mui/material";
import Sidebar from './Sidebar'
const Feed = () => {
return (
//px is for padding
//using sx and md to make the property dynamic for smaller and mrdium devices respectively
<Stack sx={{ flexDirection: { sx: "column", md: "row" } }}>
<Box
sx={{
height: { sx: "auto", md: "9200vh" },
borderRight: "100px solid #3d3d3d",
px: { sx: 0, md: 2 },
}}
>
< Sidebar/>
<Typography className="copyright" variant="body2" sx={{mt:1.5,color:'#fff'}}>
Copyright 2020 JSM Media
</Typography>
</Box>
</Stack>
)
}
export default Feed;发布于 2022-08-31 11:11:47
您似乎错过了返回语句在sidebar.jsx中,该语句将返回要在render方法中呈现的React元素。由于这个原因,您的jsx文件没有显示适当的视图。
const Sidebar = () => {
return (
<div> </div>
)
}
export default Sidebar;https://stackoverflow.com/questions/73554853
复制相似问题