Kid
Kid

Reputation: 2205

How is this variable used in this ReactJs example

I learn react and came across this code:

import React, { Component } from "react";
import Header from "./components/structure/Header";
import Content from "./components/structure/Content";
import Footer from "./components/structure/Footer";
import Resume from "./resume.json";

class App extends Component {
  componentDidMount() {
    document.title = [
      Resume.basics.name,
      Resume.basics.label,
      [Resume.basics.location.region, Resume.basics.location.country].join(", ")
    ].join(" | ");
  }

  render() {
    return (
      <div>
        <Header />
        <Content />
        <Footer />
      </div>
    );
  }
}

export default App;

What I cant figure out is how is document.title used? I cant see that it is exported or that any part of the code(other components) are using it.

Maybe it's not used and could be removed??

Upvotes: 0

Views: 21

Answers (1)

Menawer
Menawer

Reputation: 883

The variable "document" is an environment variable provided by the browser, It gives you access to various features to access the page elements, on of those features is to access the "title" of the page and read or edit it, which you can see at the top of the browser.

Upvotes: 1

Related Questions