Socket
Socket
Sign inDemoInstall

react-dom

Package Overview
Dependencies
1
Maintainers
5
Versions
1802
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-dom


Version published
Maintainers
5
Created

Package description

What is react-dom?

The react-dom package provides DOM-specific methods that can be used at the top level of a web app to enable an efficient way of managing DOM elements in response to data changes. It is a companion package to React that facilitates rendering components to the DOM and interacting with the DOM tree.

What are react-dom's main functionalities?

Rendering React Elements

This feature allows you to render a React element into the DOM in the supplied container and return a reference to the component (or returns null for stateless components).

ReactDOM.render(
  <h1>Hello, world!</h1>,
  document.getElementById('root')
);

Component Lifecycle Management

react-dom manages the lifecycle of components, including mounting, updating, and unmounting components.

class MyComponent extends React.Component {
  componentDidMount() {
    // Code to run when the component is mounted
  }

  componentWillUnmount() {
    // Code to run before the component is unmounted and destroyed
  }
}

Handling Events

react-dom provides a synthetic event system that wraps the native event system, providing a cross-browser interface to native events.

function MyComponent() {
  function handleClick(e) {
    e.preventDefault();
    console.log('The link was clicked.');
  }

  return (
    <a href="#" onClick={handleClick}>
      Click me
    </a>
  );
}

Server-side Rendering

react-dom/server provides methods for rendering components to static markup (typically used on the server) such as renderToString and renderToStaticMarkup.

ReactDOMServer.renderToString(
  <MyComponent />
);

Portals

Portals provide a way to render children into a DOM node that exists outside the DOM hierarchy of the parent component.

ReactDOM.createPortal(
  child,
  container
);

Other packages similar to react-dom

Changelog

Source

15.2.0 (July 1, 2016)

React

  • Add error codes to production invariants, with links to the view the full error text. (@keyanzhang in #6948)
  • Include component stack information in PropType validation warnings. (@troydemonbreun in #6398, @sophiebits in #6771)
  • Include component stack information in key warnings. (@keyanzhang in #6799)
  • Stop validating props at mount time, only validate at element creation. (@keyanzhang in #6824)
  • New invariant providing actionable error in missing instance case. (@yungsters in #6990)
  • Add React.PropTypes.symbol to support ES2015 Symbols as props. (@puradox in #6377)
  • Fix incorrect coercion of ref or key that are undefined in development (@gaearon in #6880)
  • Fix a false positive when passing other element’s props to cloneElement (@ericmatthys in #6268)
  • Warn if you attempt to define childContextTypes on a functional component (@Aweary in #6933)

React DOM

  • Add warning for unknown properties on DOM elements. (@jimfb in #6800, @gm758 in #7152)
  • Properly remove attributes from custom elements. (@grassator in #6748)
  • Fix invalid unicode escape in attribute name regular expression. (@nbjahan in #6772)
  • Add onLoad handling to <link> element. (@roderickhsiao in #6815)
  • Add onError handling to <source> element. (@wadahiro in #6941)
  • Handle value and defaultValue more accurately in the DOM. (@jimfb in #6406)
  • Fix events issue in environments with mutated Object.prototype. (@Weizenlol in #6886)
  • Fix issue where is="null" ended up in the DOM in Firefox. (@darobin in #6896)
  • Improved performance of text escaping by using escape-html. (@aickin in #6862)
  • Fix issue with dangerouslySetInnerHTML and SVG in Internet Explorer. (@joshhunt in #6982)
  • Fix issue with <textarea> placeholders. (@jimfb in #7002)
  • Fix controlled vs uncontrolled detection of <input type="radio"/>. (@jimfb in #7003)
  • Improve performance of updating text content. (@trueadm in #7005)
  • Ensure controlled <select> components behave the same on initial render as they do on updates. (@yiminghe in #5362)

React Perf Add-on

React CSSTransitionGroup Add-on

React Native Renderer

  • Dependencies on React Native modules use CommonJS requires instead of providesModule. (@davidaurelio in #6715)

Readme

Source

react-dom

This package serves as the entry point of the DOM-related rendering paths. It is intended to be paired with the isomorphic React, which will be shipped as react to npm.

Installation

npm install react react-dom

Usage

In the browser

var React = require('react');
var ReactDOM = require('react-dom');

class MyComponent extends React.Component {
  render() {
    return <div>Hello World</div>;
  }
}

ReactDOM.render(<MyComponent />, node);

On the server

var React = require('react');
var ReactDOMServer = require('react-dom/server');

class MyComponent extends React.Component {
  render() {
    return <div>Hello World</div>;
  }
}

ReactDOMServer.renderToString(<MyComponent />);

API

react-dom

  • findDOMNode
  • render
  • unmountComponentAtNode

react-dom/server

  • renderToString
  • renderToStaticMarkup

Keywords

FAQs

Last updated on 01 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc