Accepted answer

the main job of react is to figure out how to modify the dom to match what the components want to be rendered on the screen.

react does so by "mounting" (adding nodes to the dom), "unmounting" (removing them from the dom), and "updating" (making changes to nodes already in the dom).

how a react node is represented as a dom node and where and when it appears in the dom tree is managed by the top-level api. to get a better idea about what's going on, look at the most simple example possible:

// jsx version: let foo = <foocomponent />;
let foo = react.createelement(foocomponent);

so what is foo and what can you do with it? foo, at the moment, is a plain javascript object that looks roughly like this (simplified):

  type: foocomponent,
  props: {}

it's currently not anywhere on the page, i.e. it is not a dom element, doesn't exist anywhere in the dom tree and, aside from being react element node, has no other meaningful representation in the document. it just tells react what needs to be on the screen if this react element gets rendered. it is not "mounted" yet.

you can tell react to "mount" it into a dom container by calling:

reactdom.render(foo, domcontainer);

this tells react it's time to show foo on the page. react will create an instance of the foocomponent class and call its render method. let's say it renders a <div />, in that case react will create a div dom node for it, and insert it into the dom container.

this process of creating instances and dom nodes corresponding to react components, and inserting them into the dom, is called mounting.

note that normally you'd only call reactdom.render() to mount the root component(s). you don't need to manually "mount" the child components. every time a parent component calls setstate(), and its render method says a particular child should be rendered for the first time, react will automatically "mount" this child into its parent.


the main goal of react js is to create reusable components. here, components are the individual parts of a webpage. for example, in a webpage the header is a component, the footer is a component, a toast notification is a component and etc. the term "mount" tells us that these components are loaded or rendered in the dom. these are many top-level apis and methods dealing with this.

to make it simple, mounted means the component has been loaded to the dom and unmounted means the components has been removed from the dom.


mounting refers to the initial page loading when your react component is first rendered. from react documentation for mounting: componentdidmount:

invoked once, only on the client (not on the server), immediately after the initial rendering occurs. at this point in the lifecycle, the component has a dom representation which you can access via react.finddomnode(this).

you can contrast this with componentdidupdate function, which is called everytime that react renders (except for the initial mount).


here, componentdidmount is a method called automatically by react when a component is rendered.

the concept is that you're telling reactjs, "please take this thing, this comment box or spinning image or whatever it is i want on the browser page, and go ahead and actually put it on the browser page. when that's done, call my function that i've bound to componentdidmount so i can proceed."

componentwillmount is the opposite. it will fire immediately before your component renders.

see also here

finally, the "mount" term seems to be unique to react.js. i don't think it is a general javascript concept, or even a general browser concept.


mounting refers to the component in react (created dom nodes) being attached to some part of the document. that's it!

ignoring react you can think of these two native functions as mounting:



which are likely the most common functions react uses to mount internally.

think of:

componentwillmount === before-mount


componentdidmount === after-mount


react is an isomorphic/universal framework. that means that there is a virtual representation of the ui component tree, and that is separate from the actual rendering that it outputs in the browser. from the documentation:

react is so fast because it never talks to the dom directly. react maintains a fast in-memory representation of the dom.

however, that in-memory representation is not tied directly to the dom in the browser (even though it is called virtual dom, which is an unfortunate and confusing name for an universal apps framework), and it is just a dom-like data-structure that represents all the ui components hierarchy and additional meta-data. virtual dom is just an implementation detail.

"we think the true foundations of react are simply ideas of components and elements: being able to describe what you want to render in a declarative way. these are the pieces shared by all of these different packages. the parts of react specific to certain rendering targets aren't usually what we think of when we think of react." - react js blog

so, the conclusion is that react is rendering agnostic, which means that it doesn't care about what is the final output. it can be a dom tree in the browser, it can be xml, native components or json.

"as we look at packages like react-native, react-art, react-canvas, and react-three, it's become clear that the beauty and essence of react has nothing to do with browsers or the dom." - react js blog

now, that you know how react works, it is easy to answer your question :)

mounting is the process of outputting the virtual representation of a component into the final ui representation (e.g. dom or native components).

in a browser that would mean outputting a react element into an actual dom element (e.g. an html div or li element) in the dom tree. in a native application that would mean outputting a react element into a native component. you can also write your own renderer and output react components into json or xml or even xaml if you have the courage.

so, mounting/unmounting handlers are critical to a react application, because you can only be sure a component is output/rendered when it is mounted. however, the componentdidmount handler is invoked only when rendering to an actual ui representation (dom or native components) but not if you are rendering to an html string on the server using rendertostring, which makes sense, since the component is not actually mounted until it reaches the browser and executes in it.

and, yes, mounting is also an unfortunate/confusing name, if you ask me. imho componentdidrender and componentwillrender would be much better names.

Related Query

More Query from same tag