Socket
Socket
Sign inDemoInstall

@types/react

Package Overview
Dependencies
3
Maintainers
1
Versions
561
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

@types/react

TypeScript definitions for react

    18.2.58ts4.6ts4.7ts4.8ts4.9ts5.0ts5.1ts5.2latest
    GitHub
    npm

Version published
Maintainers
1
Weekly downloads
25,566,861
increased by10.31%

Weekly downloads

Package description

What is @types/react?

The @types/react package contains TypeScript type definitions for React (a JavaScript library for building user interfaces). It enables TypeScript developers to use React with type checking, which enhances development by catching errors early and providing autocompletion in code editors. This package is essential for developers working with React in TypeScript projects, as it defines the types for React APIs, components, hooks, and other utilities.

What are @types/react's main functionalities?

Component Type Definitions

Defines TypeScript types for React functional components, allowing for type checking of props.

import React from 'react';

interface Props {
  greeting: string;
}

const Greeting: React.FC<Props> = ({ greeting }) => <div>{greeting}</div>;

Hook Type Definitions

Provides type definitions for React hooks like useState, enabling type checking and autocompletion for hook-related code.

import React, { useState } from 'react';

const Counter: React.FC = () => {
  const [count, setCount] = useState<number>(0);
  return (
    <div>
      <p>{count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
};

Event Type Definitions

Includes type definitions for handling events in React, such as mouse and keyboard events, with appropriate type checking.

import React from 'react';

const Clicker: React.FC = () => {
  const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
    console.log('Button clicked');
  };
  return <button onClick={handleClick}>Click Me</button>;
};

Other packages similar to @types/react

Readme

Source

Installation

npm install --save @types/react

Summary

This package contains type definitions for react (https://react.dev/).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react.

Additional Details

Credits

These definitions were written by Asana, AssureSign, Microsoft, John Reilly, Benoit Benezech, Patricio Zavolinsky, Eric Anderson, Dovydas Navickas, Josh Rutherford, Guilherme Hübner, Ferdy Budhidharma, Johann Rakotoharisoa, Olivier Pascal, Martin Hochel, Frank Li, Jessica Franco, Saransh Kataria, Kanitkorn Sujautra, Sebastian Silbermann, Kyle Scully, Cong Zhang, Dimitri Mitropoulos, JongChan Choi, Victor Magalhães, Dale Tan, Priyanshu Rav, and Dmitry Semigradsky.

FAQs

Last updated on 23 Feb 2024

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the 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