Socket
Socket
Sign inDemoInstall

react-dom

Package Overview
Dependencies
1
Maintainers
6
Versions
1802
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-dom


Version published
Maintainers
6
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.3.0 (July 29, 2016)

React

  • Add React.PureComponent - a new base class to extend, replacing react-addons-pure-render-mixin now that mixins don't work with ES2015 classes. (@sophiebits in #7195)
  • Add new warning when modifying this.props.children. (@jimfb in #7001)
  • Fixed issue with ref resolution order. (@gaearon in #7101)
  • Warn when mixin is undefined. (@swaroopsm in #6158)
  • Downgrade "unexpected batch number" invariant to a warning. (@sophiebits in #7133)
  • Validate arguments to oneOf and oneOfType PropTypes sooner. (@troydemonbreun in #6316)
  • Warn when calling PropTypes directly. (@Aweary in #7132, #7194)
  • Improve warning when using Maps as children. (@keyanzhang in #7260)
  • Add additional type information to the PropTypes.element warning. (@alexzherdev in #7319)
  • Improve component identification in no-op setState warning. (@keyanzhang in #7326)

React DOM

  • Fix issue with nested server rendering. (@Aweary in #7033)
  • Add xmlns, xmlnsXlink to supported SVG attributes. (@salzhrani in #6471)
  • Add referrerPolicy to supported HTML attributes. (@Aweary in #7274)
  • Fix issue resulting in <input type="range"> initial value being rounded. (@troydemonbreun in #7251)

React Test Renderer

React Perf Add-on

  • Fix issue resulting in excessive warnings when encountering an internal measurement error. (@sassanh in #7299)

React TestUtils Add-on

  • Implement type property on for events created via TestUtils.Simulate.*. (@yaycmyk in #6154)
  • Fix crash when running TestUtils with the production build of React. (@gaearon in #7246)

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 29 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