react warning cannot set state when using promises

前端 未结 7 1316
情深已故
情深已故 2020-12-19 13:40

I\'m trying to query the server to get list of nav items so I can build my menu on init. I\'ve so far managed to create a static page with 3 contents on the home page, which

7条回答
  •  無奈伤痛
    2020-12-19 14:39

    seems like the issue was separating the code properly in different files. I had index, App with componentDidMount() all in one which was not working.

    so i have done

    index

    import React, { Component } from 'react'
    import ReactDOM from 'react-dom'
    import { Provider } from 'react-redux';
    import { createStore, applyMiddleware, combineReducers } from 'redux';
    import { BrowserRouter, Route, browserHistory } from 'react-router-dom';
    import promise from 'redux-promise';
    
    import App from './App'
    import reducers from './reducers';
    
    require("babel-core/register");
    require("babel-polyfill");
    
    const createStoreWithMiddleware = applyMiddleware(promise)(createStore);
    
    ReactDOM.render(
            
                
                    
                
            
            , document.getElementById('root'));
    

    App

    import React, { Component } from 'react'
    import { HashRouter, Switch, Route, Link } from 'react-router-dom';
    import Header from './components/header';
    import Logout from './components/logout';
    import SideBar from './components/sidebar';
    import HomeContent from './components/home';
    import Ldapuser from './components/ldapuser';
    import AdminContent from './components/getting_started/admin';
    
    const Main = () => (
        
    ) class App extends Component { render() { return (
    ); } } export default App;

    and the individual files... header etc will have componentDidMount() which now works

提交回复
热议问题