C
C
Chvalov2018-10-17 05:17:05
JavaScript
Chvalov, 2018-10-17 05:17:05

How do you know in React that a component has mounted?

There is a code:

import React, {Component} from 'react';
import {Route, Switch} from 'react-router-dom';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import ContentIndex from '../pages/ContentIndex';
import Catalog from '../pages/Catalog';

class Root extends Component {
  
  render(){
      return(
      <div className="all-data">
      <Switch>

        <Route
        exact
        path={"/"}
        component={ContentIndex}
        />

        <Route
        path={'/catalog'
        component={Catalog}
        />
              
              </Switch>
       </div>

      )
  }

}

I don’t know how to implement the template so that when the url is navigated, the spinner is loaded and, as soon as the component is mounted, hide the spinner.
The expected result is like here - https://nguyenbathanh.github.io

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
khorark, 2018-10-17
@Chvalov

The ComponentDidMount method fires when the component is mounted. Full info on React lifecycle methods here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question