Convert Figma logo to code with AI

facebook logoreact

The library for web and native user interfaces.

227,213
46,322
227,213
831

Top Related Projects

207,677

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core

95,657

Deliver web apps with confidence 🚀

78,194

Cybernetically enhanced web apps

36,546

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.

27,910

A rugged, minimal framework for composing JavaScript behavior in your markup.

32,270

A declarative, efficient, and flexible JavaScript library for building user interfaces.

Quick Overview

React is a popular JavaScript library for building user interfaces, particularly for single-page applications. It allows developers to create reusable UI components and efficiently update and render them when data changes. React is maintained by Facebook and a community of individual developers and companies.

Pros

  • Virtual DOM for efficient rendering and improved performance
  • Component-based architecture for better code organization and reusability
  • Large and active community, providing extensive resources and third-party libraries
  • Flexible integration with other libraries and existing projects

Cons

  • Steep learning curve for beginners, especially with JSX syntax and state management
  • Requires additional libraries for full-featured applications (e.g., routing, state management)
  • Frequent updates and changes in best practices can be challenging to keep up with
  • Can be overkill for simple websites or applications

Code Examples

  1. Creating a functional component:
import React from 'react';

const Greeting = ({ name }) => {
  return <h1>Hello, {name}!</h1>;
};

export default Greeting;
  1. Using hooks for state management:
import React, { useState } from 'react';

const Counter = () => {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
};
  1. Handling events:
import React from 'react';

const Button = () => {
  const handleClick = () => {
    alert('Button clicked!');
  };

  return <button onClick={handleClick}>Click me</button>;
};

Getting Started

To start a new React project, you can use Create React App:

npx create-react-app my-app
cd my-app
npm start

This will create a new React application and start a development server. You can then edit the files in the src directory to build your application.

To use React in an existing project, install it via npm:

npm install react react-dom

Then, you can import and use React in your JavaScript files:

import React from 'react';
import ReactDOM from 'react-dom';

const App = () => <h1>Hello, React!</h1>;

ReactDOM.render(<App />, document.getElementById('root'));

Competitor Comparisons

207,677

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core

Pros of Vue

  • Easier learning curve and simpler syntax
  • Better performance for small to medium-sized applications
  • More flexible and less opinionated, allowing for easier integration into existing projects

Cons of Vue

  • Smaller ecosystem and community compared to React
  • Fewer job opportunities and enterprise-level adoption
  • Less suitable for very large-scale applications

Code Comparison

Vue component:

<template>
  <div>{{ message }}</div>
</template>

<script>
export default {
  data() {
    return {
      message: 'Hello, Vue!'
    }
  }
}
</script>

React component:

import React from 'react';

function App() {
  return (
    <div>{message}</div>
  );
}

const message = 'Hello, React!';
export default App;

Vue uses a template-based approach with a more HTML-like structure, while React uses JSX, which combines JavaScript and HTML-like syntax. Vue's component structure separates template, script, and style sections, whereas React components typically combine rendering logic and presentation in a single file.

Both frameworks offer reactive updates, component-based architecture, and virtual DOM for efficient rendering. The choice between Vue and React often depends on project requirements, team expertise, and personal preference.

95,657

Deliver web apps with confidence 🚀

Pros of Angular

  • Full-featured framework with built-in tools for routing, forms, and HTTP requests
  • TypeScript support out of the box, providing better type checking and tooling
  • Dependency injection system for better modularity and testability

Cons of Angular

  • Steeper learning curve due to its comprehensive nature and TypeScript requirement
  • Larger bundle size, which can impact initial load times
  • More opinionated structure, potentially limiting flexibility in some cases

Code Comparison

Angular component:

@Component({
  selector: 'app-example',
  template: '<h1>{{ title }}</h1>'
})
export class ExampleComponent {
  title = 'Hello, Angular!';
}

React component:

function ExampleComponent() {
  const title = 'Hello, React!';
  return <h1>{title}</h1>;
}

Angular uses a decorator-based approach with TypeScript, while React employs a more functional style with JSX. Angular's component definition includes metadata, whereas React's is a simple function. Both frameworks achieve similar results but with different syntaxes and philosophies.

78,194

Cybernetically enhanced web apps

Pros of Svelte

  • Smaller bundle sizes due to compile-time optimization
  • No virtual DOM, resulting in faster runtime performance
  • Simpler, more intuitive syntax with less boilerplate code

Cons of Svelte

  • Smaller ecosystem and community compared to React
  • Fewer job opportunities and less widespread adoption
  • Limited tooling and third-party library support

Code Comparison

React:

function Counter() {
  const [count, setCount] = useState(0);
  return (
    <button onClick={() => setCount(count + 1)}>
      Clicks: {count}
    </button>
  );
}

Svelte:

<script>
  let count = 0;
</script>

<button on:click={() => count++}>
  Clicks: {count}
</button>

Summary

Svelte offers a more streamlined development experience with better performance out of the box, while React provides a mature ecosystem and widespread industry adoption. Svelte's syntax is more concise and requires less setup, but React's larger community and extensive tooling can be advantageous for complex projects. The choice between the two often depends on project requirements, team expertise, and long-term maintainability considerations.

36,546

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.

Pros of Preact

  • Significantly smaller bundle size (3KB vs React's ~40KB)
  • Faster performance due to lightweight implementation
  • API compatibility with React, allowing easy migration

Cons of Preact

  • Smaller ecosystem and community compared to React
  • Fewer advanced features and tools available
  • Less suitable for large-scale, complex applications

Code Comparison

React:

import React from 'react';
import ReactDOM from 'react-dom';

const App = () => <h1>Hello, React!</h1>;
ReactDOM.render(<App />, document.getElementById('root'));

Preact:

import { h, render } from 'preact';

const App = () => <h1>Hello, Preact!</h1>;
render(<App />, document.body);

Key Differences

  • Preact uses h instead of React's createElement
  • Preact's render function is more straightforward
  • Preact doesn't require a separate DOM package

Use Cases

  • React: Large-scale applications, complex UIs, extensive ecosystem support
  • Preact: Lightweight projects, performance-critical applications, size-constrained environments

Community and Support

React has a larger community, more resources, and extensive corporate backing. Preact, while smaller, has a dedicated community and is actively maintained.

Conclusion

Choose React for robust, feature-rich applications with a vast ecosystem. Opt for Preact when prioritizing performance and minimal bundle size in smaller projects.

27,910

A rugged, minimal framework for composing JavaScript behavior in your markup.

Pros of Alpine

  • Lightweight and minimal, with a smaller learning curve
  • No build step required, can be used directly in HTML
  • Seamless integration with existing projects

Cons of Alpine

  • Limited ecosystem and community support compared to React
  • Less suitable for large, complex applications
  • Fewer advanced features and tooling options

Code Comparison

Alpine:

<div x-data="{ open: false }">
    <button @click="open = !open">Toggle</button>
    <span x-show="open">Content</span>
</div>

React:

function Toggle() {
  const [open, setOpen] = useState(false);
  return (
    <div>
      <button onClick={() => setOpen(!open)}>Toggle</button>
      {open && <span>Content</span>}
    </div>
  );
}

Alpine is designed for simplicity and ease of use, making it ideal for adding interactivity to existing projects or building smaller applications. It excels in scenarios where a full-fledged framework like React might be overkill. However, React offers a more robust ecosystem, better performance for complex applications, and a wider range of tools and libraries. The choice between the two depends on the project's scale, complexity, and specific requirements.

32,270

A declarative, efficient, and flexible JavaScript library for building user interfaces.

Pros of Solid

  • Faster performance due to its fine-grained reactivity system
  • Smaller bundle size, resulting in quicker load times
  • More predictable and less magical API, closer to vanilla JavaScript

Cons of Solid

  • Smaller ecosystem and community compared to React
  • Fewer learning resources and third-party libraries available
  • Less widespread adoption in enterprise environments

Code Comparison

React:

function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(count + 1)}>{count}</button>;
}

Solid:

function Counter() {
  const [count, setCount] = createSignal(0);
  return <button onClick={() => setCount(count() + 1)}>{count()}</button>;
}

Key Differences

  • Solid uses signals for state management, while React uses hooks
  • Solid's reactivity is more granular, updating only what's necessary
  • React's JSX is transformed differently, requiring explicit imports
  • Solid's components are true functions, not re-rendered on each update

Conclusion

While React remains the more popular and widely-adopted framework, Solid offers compelling performance benefits and a simpler mental model. The choice between the two depends on project requirements, team expertise, and ecosystem needs.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

React · GitHub license npm version (Runtime) Build and Test (Compiler) TypeScript PRs Welcome

React is a JavaScript library for building user interfaces.

  • Declarative: React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes. Declarative views make your code more predictable, simpler to understand, and easier to debug.
  • Component-Based: Build encapsulated components that manage their own state, then compose them to make complex UIs. Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep the state out of the DOM.
  • Learn Once, Write Anywhere: We don't make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code. React can also render on the server using Node and power mobile apps using React Native.

Learn how to use React in your project.

Installation

React has been designed for gradual adoption from the start, and you can use as little or as much React as you need:

Documentation

You can find the React documentation on the website.

Check out the Getting Started page for a quick overview.

The documentation is divided into several sections:

You can improve it by sending pull requests to this repository.

Examples

We have several examples on the website. Here is the first one to get you started:

import { createRoot } from 'react-dom/client';

function HelloMessage({ name }) {
  return <div>Hello {name}</div>;
}

const root = createRoot(document.getElementById('container'));
root.render(<HelloMessage name="Taylor" />);

This example will render "Hello Taylor" into a container on the page.

You'll notice that we used an HTML-like syntax; we call it JSX. JSX is not required to use React, but it makes code more readable, and writing it feels like writing HTML.

Contributing

The main purpose of this repository is to continue evolving React core, making it faster and easier to use. Development of React happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving React.

Code of Conduct

Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Contributing Guide

Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React.

Good First Issues

To help you get your feet wet and get you familiar with our contribution process, we have a list of good first issues that contain bugs that have a relatively limited scope. This is a great place to get started.

License

React is MIT licensed.

NPM DownloadsLast 30 Days