Socket
Socket
Sign inDemoInstall

react-dom

Package Overview
Dependencies
4
Maintainers
7
Versions
1802
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-dom


Version published
Maintainers
7
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.4.0 (November 16, 2016)

React

  • React package and browser build no longer "secretly" includes React DOM. (@sebmarkbage in #7164 and #7168)
  • Required PropTypes now fail with specific messages for null and undefined. (@chenglou in #7291)
  • Improved development performance by freezing children instead of copying. (@keyanzhang in #7455)

React DOM

  • Fixed occasional test failures when React DOM is used together with shallow renderer. (@goatslacker in #8097)
  • Added a warning for invalid aria- attributes. (@jessebeach in #7744)
  • Added a warning for using autofocus rather than autoFocus. (@hkal in #7694)
  • Removed an unnecessary warning about polyfilling String.prototype.split. (@nhunzaker in #7629)
  • Clarified the warning about not calling PropTypes manually. (@jedwards1211 in #7777)
  • The unstable batchedUpdates API now passes the wrapped function's return value through. (@bgnorlov in #7444)
  • Fixed a bug with updating text in IE 8. (@mnpenner in #7832)

React Perf

  • When ReactPerf is started, you can now view the relative time spent in components as a chart in Chrome Timeline. (@gaearon in #7549)

React Test Utils

  • If you call Simulate.click() on a <input disabled onClick={foo} /> then foo will get called whereas it didn't before. (@nhunzaker in #7642)

React Test Renderer

  • Due to packaging changes, it no longer crashes when imported together with React DOM in the same file. (@sebmarkbage in #7164 and #7168)
  • ReactTestRenderer.create() now accepts {createNodeMock: element => mock} as an optional argument so you can mock refs with snapshot testing. (@Aweary in #7649, #8261)

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 16 Nov 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