Socket
Socket
Sign inDemoInstall

react

Package Overview
Dependencies
33
Maintainers
2
Versions
1790
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react

React is a JavaScript library for building user interfaces.


Version published
Weekly downloads
23M
decreased by-1.4%
Maintainers
2
Install size
6.68 MB
Created
Weekly downloads
 

Package description

What is react?

The react npm package is a JavaScript library for building user interfaces, particularly for single-page applications. It allows developers to create reusable UI components and manage the state of their applications efficiently.

What are react's main functionalities?

Component-Based Architecture

React allows developers to encapsulate UI logic and design into components, which can then be composed to build complex user interfaces.

class Welcome extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>;
  }
}
ReactDOM.render(<Welcome name='Jane' />, document.getElementById('root'));

State Management

React provides a way to manage the state within components, enabling dynamic and interactive user interfaces.

class Counter extends React.Component {
  constructor(props) {
    super(props);
    this.state = { count: 0 };
  }
  increment = () => {
    this.setState({ count: this.state.count + 1 });
  };
  render() {
    return (
      <div>
        <p>{this.state.count}</p>
        <button onClick={this.increment}>Increment</button>
      </div>
    );
  }
}

Lifecycle Methods

React components come with lifecycle methods that are invoked at specific points in a component's lifecycle, allowing developers to hook into the component's creation, updating, and destruction processes.

class Timer extends React.Component {
  componentDidMount() {
    this.timerID = setInterval(() => this.tick(), 1000);
  }
  componentWillUnmount() {
    clearInterval(this.timerID);
  }
  tick() {
    this.setState({
      date: new Date()
    });
  }
  render() {
    return (
      <div>
        <h2>It is {this.state.date.toLocaleTimeString()}.</h2>
      </div>
    );
  }
}

Hooks

Hooks are functions that let developers 'hook into' React state and lifecycle features from function components. They provide a way to use stateful logic without writing a class.

import { useState, useEffect } from 'react';

function Example() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    document.title = `You clicked ${count} times`;
  });

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}

Other packages similar to react

Changelog

Source

0.12.0 (October 28, 2014)

React Core

Breaking Changes
  • key and ref moved off props object, now accessible on the element directly
  • React is now BSD licensed with accompanying Patents grant
  • Default prop resolution has moved to Element creation time instead of mount time, making them effectively static
  • React.__internals is removed - it was exposed for DevTools which no longer needs access
  • Composite Component functions can no longer be called directly - they must be wrapped with React.createFactory first. This is handled for you when using JSX.
New Features
  • Spread operator ({...}) introduced to deprecate this.transferPropsTo
  • Added support for more HTML attributes: acceptCharset, classID, manifest
Deprecations
  • React.renderComponent --> React.render
  • React.renderComponentToString --> React.renderToString
  • React.renderComponentToStaticMarkup --> React.renderToStaticMarkup
  • React.isValidComponent --> React.isValidElement
  • React.PropTypes.component --> React.PropTypes.element
  • React.PropTypes.renderable --> React.PropTypes.node
  • DEPRECATED React.isValidClass
  • DEPRECATED instance.transferPropsTo
  • DEPRECATED Returning false from event handlers to preventDefault
  • DEPRECATED Convenience Constructor usage as function, instead wrap with React.createFactory
  • DEPRECATED use of key={null} to assign implicit keys
Bug Fixes
  • Better handling of events and updates in nested results, fixing value restoration in "layered" controlled components
  • Correctly treat event.getModifierState as case sensitive
  • Improved normalization of event.charCode
  • Better error stacks when involving autobound methods
  • Removed DevTools message when the DevTools are installed
  • Correctly detect required language features across browsers
  • Fixed support for some HTML attributes:
    • list updates correctly now
    • scrollLeft, scrollTop removed, these should not be specified as props
  • Improved error messages

React With Addons

New Features
  • React.addons.batchedUpdates added to API for hooking into update cycle
Breaking Changes
  • React.addons.update uses assign instead of copyProperties which does hasOwnProperty checks. Properties on prototypes will no longer be updated correctly.
Bug Fixes
  • Fixed some issues with CSS Transitions

JSX

Breaking Changes
  • Enforced convention: lower case tag names are always treated as HTML tags, upper case tag names are always treated as composite components
  • JSX no longer transforms to simple function calls
New Features
  • @jsx React.DOM no longer required
  • spread ({...}) operator introduced to allow easier use of props
Bug Fixes
  • JSXTransformer: Make sourcemaps an option when using APIs directly (eg, for react-rails)

Readme

Source

react

An npm package to get you immediate access to React, without also requiring the JSX transformer. This is especially useful for cases where you want to browserify your module using React.

Note: by default, React will be in development mode. The development version includes extra warnings about common mistakes, whereas the production version includes extra performance optimizations and strips all error messages.

To use React in production mode, set the environment variable NODE_ENV to production. A minifier that performs dead-code elimination such as UglifyJS is recommended to completely remove the extra code present in development mode.

Example Usage

var React = require('react');

// You can also access ReactWithAddons.
var React = require('react/addons');

Keywords

FAQs

Last updated on 28 Oct 2014

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc