ReactDOM 不会渲染应用程序,即使应用程序'compiles sucessfully'



我遇到了一个问题,reactDOM.render尽管成功地编译了yarn,但它并没有呈现应用程序。

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import {Provider} from 'react-redux';
import {PersistGate} from 'redux-persist/integration/react';
import {store ,persistor} from './redux/store.js'
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<PersistGate persistor={persistor}>
<App />
</PersistGate>
</Provider>
</React.StrictMode>,
document.getElementById('root')
);

store.js 中的Redux配置

import { createStore, applyMiddleware } from 'redux';
import logger from 'redux-logger';
import {persistStore} from 'redux-persist';
import createSagaMiddleware from 'redux-saga';
import { fetchGalleryStart } from './gallery/gallery.saga';
import {rootReducer} from './root.reducer.js';
const sagaMiddleware= createSagaMiddleware();
const middlewares = [sagaMiddleware];
if (process.env.NODE_ENV==='development') {
middlewares.push(logger)
}
export const store = createStore(rootReducer, applyMiddleware(...middlewares));
export const persistor = persistStore(store);
sagaMiddleware.run(fetchGalleryStart); //inside run we pass each individual saga
const exportedObject = {
store,
persistor,
};
export default exportedObject;

apps

import React from 'react';
import { BrowserRouter, Switch, Route } from "react-router-dom";
import Header from './components/header/header.component.jsx';
import Footer from './components/footer/footer.component.jsx';
import HomePage from './pages/homepage/homepage.component.jsx';
import Contact from './pages/contact/contact.component.jsx';
import About from './pages/about/about.component.jsx';
class App extends React.Component  {

render () {
return (
<div className="App">
<BrowserRouter>
<Header />
<div className="wrapper">
<Switch>
<Route exact path="/" component={HomePage} />
<Route path="/contact" component={Contact} />
<Route path="/about" component={About} />
<Route path="*">error</Route>
</Switch>
</div>
<Footer/>
</BrowserRouter>
</div>
);
}

};
export default  App

当我在浏览器中打开应用程序时,该应用程序不会在根上呈现,页面保持空白。你能帮我找哪里吗?由于我没有收到任何错误,我非常不知道如何处理这个问题。

感谢您抽出时间

包装渲染((。。。方法的类组件如下:

class App extends React.Component {
render() {
return ();
}
}
export default App;

声明应用程序正确。或者去掉render((方法,做一个函数:

funciton App() => {
return (<div></div>);
}
export default App;

希望我能帮助你,玩得开心!

相关内容

  • 没有找到相关文章

最新更新