sbusso / React-Practice

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React Mental Models

React helps us build complex, interactive UIs more easily than ever before. It also encourages us to write code in a certain way, guiding us to create apps that are simpler to navigate and understand.

An abstract model inside a mind looking at the React logo

React itself is a mental model with a simple idea at its core: encapsulate portions of your app that rely on similar logic and UI and React will make sure that portion is always up kept up to date.

Whether you've been working with React for years or are just starting, having a clear mental model is the best way to feel confident working with it. So for me to transfer my mental models to you I'll start from first-principles and build on top of them.

It's functions all the way down

Let's start by modeling the basic building blocks of JavaScript and React: functions.

  • A React component is just a function
  • Components containing other components are functions calling other functions
  • Props are the function's arguments

This is hidden away by JSX, the markup language React uses. Strip away JSX and React is a bunch of functions calling one another. JSX is in itself an applied mental model that makes using React simpler and more intuitive.

Let's look at each part individually.

A component is a function that returns JSX

React is used with JSX—JavaScript XML—a way to write what seems as HTML with all of JavaScript's power. JSX offers a great applied mental model for using nested functions in a way that feels intuitive.

Let's ignore class components and focus on the far more common functional components. A functional component is a function that behaves exactly like any other JavaScript function. React components always return JSX which is then executed and turned into HTML.

This is what simple JSX looks like:

    const Li = props => <li {...props}>{props.children}</li>;
    
    export const RickRoll = () => (
      <div>
        <div className='wrapper'>
          <ul>
            <Li color={'red'}>Never give you up</Li>
          </ul>
        </div>
      </div>
    );

Which compiled into pure JavaScript by Babel:

    const Li = props => React.createElement('li', props, props.children);
    
    export const RickRoll = () =>
      React.createElement(
        'div',
        null,
        React.createElement(
          'div',
          {
            className: 'wrapper',
          },
          React.createElement(
            'ul',
            null,
            React.createElement(
              Li,
              {
                color: 'red',
              },
              'Never give you up',
            ),
          ),
        ),
      );

Now, notice how each component is a function calling another function, and each new component is the third argument for the React.createElement function. Whenever you write a component, it's useful to keep in mind that it's a normal JavaScript function.

An important feature of React is that a component can have many children but only one parent. I found this a confusing until I realized it's the same logic HTML has, where each element must be inside other elements, and can have many children. You can notice this in the code above, where there's only one parent div containing all the children.

component's props are the same as a function's arguments

When using a function we can use arguments to share information with that function. For React components we call these arguments props (funny story, I didn't realize props is short for properties for a long time).

Under the hood, props behave exactly like function arguments, the differences are that we interact with them through the nicer interface of JSX, and that React gives extra functionality to props such as children .

Creating a mental model around functions

Using this knowledge let's craft a mental model to intuitively understand functions!

When I think about a function I imagine it as a box, and that box will do something whenever it's called. It could return a value or not:

    function sum(a, b) {
        return a + b;
    }

    console.log(sum(10, 20));

    function logSum(a, b) {
        console.log(a + b);
    }

Since a component is a fancy function, that makes a component a box as well, with props as the ingredients the box needs to create the output.

A plus B in a box with props explaining a mental model for JavaScript functions

When a component is executed it will run whatever logic it has, if any, and evaluate its JSX. Any tags will become HTML and any component will be executed, and the process is repeated until reaching the last component in the chain of children.

Since a component can have many children but only one parent I imagine multiple components as a set of boxes, one inside another. Each box must be contained within a bigger box and can have many smaller boxes inside.

One big box with many smaller boxes inside and text saying "it's a box in another box"

But the mental model of a box representing a component is not complete without understanding how it can interact with other boxes.

How To Think About Closures

Closures are a core concept in JavaScript. They enable complex functionality in the language, they're super important to understand to have a good mental model around React.

They're also one of the features newcomers struggle with the most, so instead of explaining the technicalities I'll demonstrate the mental model I have around closures.

The basic description of a closure is that it's a function. I imagine it as a box that keeps what's inside of it from spilling out, while allowing the things outside of it from entering, like a semi-permeable box. But spilling out where?

While the closure itself is a box, any closure will be inside bigger boxes, with the outermost box being the Window object.

A box describing a mental model of a javascript closure, showing Window, scripts and React apps

The window object encapsulates everything else

But what is a closure?

A closure is a feature of JavaScript functions. If you're using a function, you're using a closure.

As I've mentioned, a function is a box and that makes a closure a box too. Considering that each function can contain many others inside of it, then the closure is the ability of a function to use the information outside of it, while keeping the information it has inside from "spilling out", or being used by the outer function.

Speaking in terms of my mental model: I imagine the functions as boxes within boxes, and each smaller box can see the information of the outer box, or parent, but the big box cannot see the smaller one's information. That's as simple and accurate an explanation of closures as I can make.

Visual representation of closures and the sharing of information between functions in a mental model, from a box view and a tree view

"Each function can only access its own

(information and the parent's")

Each function can only access its own information and the parent's

Closures are important because they can be exploited to create some powerful mechanics and React takes full advantage of this.

Closures in React

Each React component is also a closure. Within components, you can only pass props down from parent to child and the parent cannot see what's inside the child, this is an intended feature to make our app's data flow simpler to trace. To find where data comes from, we usually need to go up the tree to find which parent is sending it down.

A great example of closures in React is updating a parent's state through a child component. You've probably done this without realizing you were messing around with closures.

To start, we know the parent can't access the child's information directly, but the child can access the parent's. So we send down that info from parent to child through props . In this case, the information takes the shape of a function that updates the parent's state.

    const Parent = () => {
      const [count, setCount] = useState(0);
    
      return (
        <div>
          The count is {count}
          <div>
            <ChildButtons onClick={setCount} count={count} />
          </div>
        </div>
      );
    };
    
    const ChildButtons = props => (
      <div>
        <button onClick={() => props.onClick(props.count + 1)}>
          Increase count
        </button>
        <button onClick={() => props.onClick(props.count - 1)}>
          Decrease count
        </button>
      </div>
    );

When an onClick happens in a button , that will execute the function received from props props.onClick , and update the value using props.count .

The insight here lies in the way we're updating a parent's state through a child, in this case, the props.onClick function. The reason this works is that the function was declared within the Parent component's scope, within its closure, so it will have access to the parent's information. Once that function is called in a child, it still lives in the same closure.

This can be hard to grasp, so the way I imagine it is as a "tunnel" between closures. Each has its own scope, but we can create a one-way communication tunnel that connects both.

Once we understand how closures affect our components, we can take the next big step: React state.

Fitting React's State Into Our Mental Model

React's philosophy is simple: it handles when and how to render elements, and developers control what to render. State is our tool to decide that what.

When state changes, its component renders and therefore re-executes all the code within. We do this to show new, updated information to the user.

In my mental model state is like a special property inside the box. It's independent of everything else that happens within it. It will get a default value on the first render and always be up to date with the latest value.

Each variable and function is created on every render, which means their values are also brand new. Even if a variable's value never changes, it is recalculated and reassigned every time. That's not the case with state, it only changes when there's a request for it to change via a set state event.

React component state visualized as a part of a bigger box with props coming in from outside

State is a special, independent part of the box; with props coming from outside

State follows a simple rule: Whenever it changes it will re-rendered the component and its children. Props follow the same logic, if a prop changes, the component will re-render, however, we can control state by modifying it, props are more static and usually change as a reaction to a state change.

the-rendering-mental-model-understanding-reacts-magic

The Rendering Mental Model: understanding React's magic


I consider rendering to be React's most confusing part because a lot of things happen during rendering that sometimes isn't obvious by looking at the code. That's why having a clear mental model helps.

The way I imagine rendering with my imaginary boxes is two-fold: the first render brings the box into existence, that's when the state is initialized. The second part is when it re-renders, that's the box being recycled, most of it is brand new but some important elements of it remain namely state.

On every render, everything inside a component is created, including variables and functions, that's why we can have variables storing a calculation's results, since they will be recalculated on every render. It's also why functions are not reliable as values, due to their reference (the function's value, per se) being different every render.

    const Thumbnail = props => (
      <div>
        {props.withIcon && <AmazingIcon />}
        <img src={props.imgUrl} alt={props.alt} />
      </div>
    );

The above will give a different result depending on the props the component receives. The reason React must re-render on every prop change is that it wants to keep the user up to date with the latest information.

However, the state doesn't change on re-renders, its value is maintained. That's why the box is "recycled" instead of created brand new every time. Internally, React is keeping track of each box and making sure its state is always consistent. That's how React knows when to update a component.

Mental model of a React component re-rendering when props change

"When props (or state) changes, a new render happens and the component's output can change")]

When props (or state) changes, a new render happens and the component's output can change

By imagining a box being recycled I can understand what's going on inside of it. For simple components, it's easy to grasp, but the more complex a component becomes, the more props it receives, the more state it maintains, the more useful a clear mental model becomes.

A complete React mental model: Putting it all together.

Now that I've explained all the different parts of the puzzle separately, let's put it all together. Here's the complete mental model I use for React components, directly translated from how I imagine them into words.

I imagine a React component as a box that contains all of its information within its walls, including its children, which are more boxes.

And like a box in the real world, it can have other boxes inside of it and these boxes can, in turn, contain more boxes. That way each box/component must have a single parent, and a parent can have many children.

Basic representation of a React component as a mental model using boxes

("The basic representation of a React component")

The basic representation of a React component

The boxes are semi-permeable, meaning they never leak anything to the outside but can use information from the outside as if it belonged to them. I imagine like this to represent how closures work in JavaScript.

In React the way to share information between components is called props , the same idea applies to function and then it's called arguments , they both work in the same way but with a different syntax.

Within components, information can only travel down from parents to children. In other words, children can access their parent's data and state, but not the other way around, and the way we share that information is through props .

I imagine this directional sharing of information as boxes within boxes. With the inner-most box being able to absorb the parent's data.

 React Mental model of data sharing between components visualized as information flowing downward

Data is shared from parent to child

The box must first be created though, and this happens on render , where the default value is given to state and just like with functions, all the code within the component is executed. In my mental model, this is equivalent to the box being created.

Subsequent renders, or re-renders , execute all the code in the component again, recalculating variables, recreating functions, and so on. Everything except for state is brand new on each render. State's value is maintained across renders is updated only through a set method.

In my mental model, I see re-rendering as recycling the box since most of it is recreated, but it's still the same box due to React keeping track of the component's state.

When a box is recycled all the boxes within it, its children, are also recycled. This can happen because the component's state was modified or a prop changed.

Mental model of a React component re-rendering when props or state change

Mental model of a React component re-rendering when props or state change

Remember that a state or prop changing means the information the user sees is outdated, and React always wants to keep the UI updated so it re-renders the component that must show the new data.

---React Mental Models

React helps us build complex, interactive UIs more easily than ever before. It also encourages us to write code in a certain way, guiding us to create apps that are simpler to navigate and understand.

An abstract model inside a mind looking at the React logo

React itself is a mental model with a simple idea at its core: encapsulate portions of your app that rely on similar logic and UI and React will make sure that portion is always up kept up to date.

Whether you've been working with React for years or are just starting, having a clear mental model is the best way to feel confident working with it. So for me to transfer my mental models to you I'll start from first-principles and build on top of them.

It's functions all the way down

Let's start by modeling the basic building blocks of JavaScript and React: functions.

  • A React component is just a function
  • Components containing other components are functions calling other functions
  • Props are the function's arguments

This is hidden away by JSX, the markup language React uses. Strip away JSX and React is a bunch of functions calling one another. JSX is in itself an applied mental model that makes using React simpler and more intuitive.

Let's look at each part individually.

A component is a function that returns JSX

React is used with JSX—JavaScript XML—a way to write what seems as HTML with all of JavaScript's power. JSX offers a great applied mental model for using nested functions in a way that feels intuitive.

Let's ignore class components and focus on the far more common functional components. A functional component is a function that behaves exactly like any other JavaScript function. React components always return JSX which is then executed and turned into HTML.

This is what simple JSX looks like:

    const Li = props => <li {...props}>{props.children}</li>;
    
    export const RickRoll = () => (
      <div>
        <div className='wrapper'>
          <ul>
            <Li color={'red'}>Never give you up</Li>
          </ul>
        </div>
      </div>
    );

Which compiled into pure JavaScript by Babel:

    const Li = props => React.createElement('li', props, props.children);
    
    export const RickRoll = () =>
      React.createElement(
        'div',
        null,
        React.createElement(
          'div',
          {
            className: 'wrapper',
          },
          React.createElement(
            'ul',
            null,
            React.createElement(
              Li,
              {
                color: 'red',
              },
              'Never give you up',
            ),
          ),
        ),
      );

Now, notice how each component is a function calling another function, and each new component is the third argument for the React.createElement function. Whenever you write a component, it's useful to keep in mind that it's a normal JavaScript function.

An important feature of React is that a component can have many children but only one parent. I found this a confusing until I realized it's the same logic HTML has, where each element must be inside other elements, and can have many children. You can notice this in the code above, where there's only one parent div containing all the children.

component's props are the same as a function's arguments

When using a function we can use arguments to share information with that function. For React components we call these arguments props (funny story, I didn't realize props is short for properties for a long time).

Under the hood, props behave exactly like function arguments, the differences are that we interact with them through the nicer interface of JSX, and that React gives extra functionality to props such as children .

Creating a mental model around functions

Using this knowledge let's craft a mental model to intuitively understand functions!

When I think about a function I imagine it as a box, and that box will do something whenever it's called. It could return a value or not:

    function sum(a, b) {
        return a + b;
    }

    console.log(sum(10, 20));

    function logSum(a, b) {
        console.log(a + b);
    }

Since a component is a fancy function, that makes a component a box as well, with props as the ingredients the box needs to create the output.

A plus B in a box with props explaining a mental model for JavaScript functions

(" ")

When a component is executed it will run whatever logic it has, if any, and evaluate its JSX. Any tags will become HTML and any component will be executed, and the process is repeated until reaching the last component in the chain of children.

Since a component can have many children but only one parent I imagine multiple components as a set of boxes, one inside another. Each box must be contained within a bigger box and can have many smaller boxes inside.

One big box with many smaller boxes inside and text saying "it's a box in another box"

But the mental model of a box representing a component is not complete without understanding how it can interact with other boxes.

How To Think About Closures

Closures are a core concept in JavaScript. They enable complex functionality in the language, they're super important to understand to have a good mental model around React.

They're also one of the features newcomers struggle with the most, so instead of explaining the technicalities I'll demonstrate the mental model I have around closures.

The basic description of a closure is that it's a function. I imagine it as a box that keeps what's inside of it from spilling out, while allowing the things outside of it from entering, like a semi-permeable box. But spilling out where?

While the closure itself is a box, any closure will be inside bigger boxes, with the outermost box being the Window object.

A box describing a mental model of a javascript closure, showing Window, scripts and React apps

The window object encapsulates everything else

But what is a closure?

A closure is a feature of JavaScript functions. If you're using a function, you're using a closure.

As I've mentioned, a function is a box and that makes a closure a box too. Considering that each function can contain many others inside of it, then the closure is the ability of a function to use the information outside of it, while keeping the information it has inside from "spilling out", or being used by the outer function.

Speaking in terms of my mental model: I imagine the functions as boxes within boxes, and each smaller box can see the information of the outer box, or parent, but the big box cannot see the smaller one's information. That's as simple and accurate an explanation of closures as I can make.

Visual representation of closures and the sharing of information between functions in a mental model, from a box view and a tree view

"Each function can only access its own

Each function can only access its own information and the parent's

Closures are important because they can be exploited to create some powerful mechanics and React takes full advantage of this.

Closures in React

Each React component is also a closure. Within components, you can only pass props down from parent to child and the parent cannot see what's inside the child, this is an intended feature to make our app's data flow simpler to trace. To find where data comes from, we usually need to go up the tree to find which parent is sending it down.

A great example of closures in React is updating a parent's state through a child component. You've probably done this without realizing you were messing around with closures.

To start, we know the parent can't access the child's information directly, but the child can access the parent's. So we send down that info from parent to child through props . In this case, the information takes the shape of a function that updates the parent's state.

    const Parent = () => {
      const [count, setCount] = useState(0);
    
      return (
        <div>
          The count is {count}
          <div>
            <ChildButtons onClick={setCount} count={count} />
          </div>
        </div>
      );
    };
    
    const ChildButtons = props => (
      <div>
        <button onClick={() => props.onClick(props.count + 1)}>
          Increase count
        </button>
        <button onClick={() => props.onClick(props.count - 1)}>
          Decrease count
        </button>
      </div>
    );

When an onClick happens in a button , that will execute the function received from props props.onClick , and update the value using props.count .

The insight here lies in the way we're updating a parent's state through a child, in this case, the props.onClick function. The reason this works is that the function was declared within the Parent component's scope, within its closure, so it will have access to the parent's information. Once that function is called in a child, it still lives in the same closure.

This can be hard to grasp, so the way I imagine it is as a "tunnel" between closures. Each has its own scope, but we can create a one-way communication tunnel that connects both.

Once we understand how closures affect our components, we can take the next big step: React state.

Fitting React's State Into Our Mental Model

React's philosophy is simple: it handles when and how to render elements, and developers control what to render. State is our tool to decide that what.

When state changes, its component renders and therefore re-executes all the code within. We do this to show new, updated information to the user.

In my mental model state is like a special property inside the box. It's independent of everything else that happens within it. It will get a default value on the first render and always be up to date with the latest value.

Each variable and function is created on every render, which means their values are also brand new. Even if a variable's value never changes, it is recalculated and reassigned every time. That's not the case with state, it only changes when there's a request for it to change via a set state event.

React component state visualized as a part of a bigger box with props coming in from outside

State is a special, independent part of the box; with props coming from outside

State follows a simple rule: Whenever it changes it will re-rendered the component and its children. Props follow the same logic, if a prop changes, the component will re-render, however, we can control state by modifying it, props are more static and usually change as a reaction to a state change.

the-rendering-mental-model-understanding-reacts-magic

The Rendering Mental Model: understanding React's magic


I consider rendering to be React's most confusing part because a lot of things happen during rendering that sometimes isn't obvious by looking at the code. That's why having a clear mental model helps.

The way I imagine rendering with my imaginary boxes is two-fold: the first render brings the box into existence, that's when the state is initialized. The second part is when it re-renders, that's the box being recycled, most of it is brand new but some important elements of it remain namely state.

On every render, everything inside a component is created, including variables and functions, that's why we can have variables storing a calculation's results, since they will be recalculated on every render. It's also why functions are not reliable as values, due to their reference (the function's value, per se) being different every render.

    const Thumbnail = props => (
      <div>
        {props.withIcon && <AmazingIcon />}
        <img src={props.imgUrl} alt={props.alt} />
      </div>
    );

The above will give a different result depending on the props the component receives. The reason React must re-render on every prop change is that it wants to keep the user up to date with the latest information.

However, the state doesn't change on re-renders, its value is maintained. That's why the box is "recycled" instead of created brand new every time. Internally, React is keeping track of each box and making sure its state is always consistent. That's how React knows when to update a component.

Mental model of a React component re-rendering when props change

"When props (or state) changes, a new render happens and the component's output can change")]

When props (or state) changes, a new render happens and the component's output can change

By imagining a box being recycled I can understand what's going on inside of it. For simple components, it's easy to grasp, but the more complex a component becomes, the more props it receives, the more state it maintains, the more useful a clear mental model becomes.

A complete React mental model: Putting it all together.

Now that I've explained all the different parts of the puzzle separately, let's put it all together. Here's the complete mental model I use for React components, directly translated from how I imagine them into words.

I imagine a React component as a box that contains all of its information within its walls, including its children, which are more boxes.

And like a box in the real world, it can have other boxes inside of it and these boxes can, in turn, contain more boxes. That way each box/component must have a single parent, and a parent can have many children.

Basic representation of a React component as a mental model using boxes

("The basic representation of a React component")

The basic representation of a React component

The boxes are semi-permeable, meaning they never leak anything to the outside but can use information from the outside as if it belonged to them. I imagine like this to represent how closures work in JavaScript.

In React the way to share information between components is called props , the same idea applies to function and then it's called arguments , they both work in the same way but with a different syntax.

Within components, information can only travel down from parents to children. In other words, children can access their parent's data and state, but not the other way around, and the way we share that information is through props .

I imagine this directional sharing of information as boxes within boxes. With the inner-most box being able to absorb the parent's data.

 React Mental model of data sharing between components visualized as information flowing downward

Data is shared from parent to child

The box must first be created though, and this happens on render , where the default value is given to state and just like with functions, all the code within the component is executed. In my mental model, this is equivalent to the box being created.

Subsequent renders, or re-renders , execute all the code in the component again, recalculating variables, recreating functions, and so on. Everything except for state is brand new on each render. State's value is maintained across renders is updated only through a set method.

In my mental model, I see re-rendering as recycling the box since most of it is recreated, but it's still the same box due to React keeping track of the component's state.

When a box is recycled all the boxes within it, its children, are also recycled. This can happen because the component's state was modified or a prop changed.

Mental model of a React component re-rendering when props or state change

Mental model of a React component re-rendering when props or state change

Remember that a state or prop changing means the information the user sees is outdated, and React always wants to keep the UI updated so it re-renders the component that must show the new data.



REACT RESOURCES:


React

JavaScript Library for building User Interfaces

React General Resources

React Community

React Online Playgrounds

React Tutorials

React General Tutorials
React Hooks
React and TypeScript
React Performance
React Internals
React Interview Questions

React Tools

React Development Tools
React Frameworks
  • next.js - The React Framework
  • gatsby.js - Free and open source framework based on React
  • react-admin - Frontend Framework for building B2B applications on top of REST/GraphQL APIs
  • remix - Finally, a killer React framework from the creators of React Router
  • aleph.js - The React Framework in Deno
React Styling
  • styled-components - Visual primitives for the component age
  • emotion - Library designed for writing CSS styles with JavaScript
  • radium - A toolchain for React component styling
  • jss - Authoring tool for CSS
  • aphrodite - Framework-agnostic CSS-in-JS with support for server-side rendering, browser prefixing, and minimum CSS generation
React Routing
  • react-router - Declarative routing for React
  • navi - Declarative, asynchronous routing for React
  • curi - JavaScript router for single-page applications
  • reach - Next Generation Routing for React
  • universal-router - A simple middleware-style router for isomorphic JavaScript web apps
React Component Libraries
  • material-ui - React components for faster and easier web development
  • ant-design - A design system with values of Nature and Determinacy
  • blueprint - A React-based UI toolkit for the webs
  • Fluent UI - A set of React components for building Microsoft web experiences
  • react-bootstrap - Bootstrap components built with React
  • reactstrap - Simple React Bootstrap 4 components
  • semantic-ui-react - The official Semantic-UI-React integration
  • evergreen - Evergreen React UI Framework by Segment
  • grommet - A react-based framework that provides accessibility, modularity, responsiveness, and theming in a tidy package
  • chakra-ui - Simple, Modular & Accessible UI Components for your React Applications
  • rebass - React primitive UI components built with styled-system
  • react-fontawesome - Font Awesome 5 component library for React
  • reakit - Accessible, Composable and Customizable components for React
  • rsuite - A suite of React components
  • atlaskit - Atlassian's official UI library, built according to the Atlassian Design Guidelines.
  • baseweb - Base Web is a foundation for initiating, evolving, and unifying web products.
  • primereact - A complete UI Framework for React with 50+ components featuring material, bootstrap and custom themes.
  • react-bulma-components - React components for Bulma framework
  • react-bulma - React.js components for Modern CSS framework based on Flexbox
  • rbx - The Comprehensive Bulma UI Framework for React
  • trunx - Super Saiyan React components, son of awesome Bulma, implemented in TypeScript
  • tailwind-react-ui - React utility component primitives & UI framework for use with Tailwind CSS
  • tails-ui - Clean UI based on tailwindcss
  • geist-org/react - Modern and minimalist React UI library, originating from Vercel's design
  • elastic ui framework - The Elastic UI Framework is a collection of React UI components for quickly building user interfaces at Elastic.
  • bugbag react ui kit - Bumbag is a friendly React UI Kit suitable for MVPs or large-scale applications.
  • ring-ui - JetBrains Web UI components
  • ChatUI - The UI design language and React library for Conversational UI
React Awesome Components
React for Command Line
  • ink - React for interactive command-line apps
  • react-blessed - A React renderer for blessed terminal interface library
React Testing
React Libraries
  • react-border-wrapper - A wrapper for placing elements along div borders in React.
  • react-magic - Automatically AJAXify plain HTML with the power of React
  • react-toolbox - A set of React components implementing Google's Material Design specification
  • tcomb-react - Library allowing you to check all the props of your React components
  • react-responsive - Media queries in react for responsive design
  • react-cursor - Functional state management abstraction for use with Facebook React
  • Touchstonejs - React.js powered UI framework for developing beautiful hybrid mobile apps.
  • Elemental - A UI Toolkit for React.js Websites and Apps
  • StateTrooper - Centrally manage state for React applications with CSP
  • Preact - Fast 3kb React alternative with the same ES6 API.
  • riotjs - A React-like, 3.5KB user interface library
  • Maple.js - Bringing the concept of web-components to React
  • react-i13n - A performant, scalable and pluggable approach to instrumenting your React application
  • react-icons - svg react icons of popular icon packs
  • react-open-doodles - Awesome free illustrations as react components.
  • Keo - Plain functions for a more functional Deku approach to creating React components, with functional goodies such as pipe, memoize, etc...
  • Bit - A virtual repository for managing and using react and other web components across applications
  • AtlasKit - Atlassian's React UI library
  • ReactiveSearch - UI components library for Elasticsearch
  • Slate - A completely customizable framework for building rich text editors.
  • react-json-schema - Construct React elements from JSON by mapping JSON definitions to React components that you expose.
  • compose-state - Compose multiple setState or getDerivedStateFromProps updaters in React
  • react-lodash - Lodash as React components
  • react-helmet - A document head manager for React
  • Stator - Simple, plain JavaScript state management with built-in support for React
  • ClearX - Fast & Effortless State management for React with zero learning curve. ClearX gives great flexibility in separation of concerns for your React applications
  • react-snap - Zero-configuration framework-agnostic static prerendering for SPAs
  • Draft.js - A React framework for building text editors
  • refract - Harness the power of reactive programming to supercharge your components
  • react-desktop - OS X and Windows UI components built with React
  • Reapop - A React & Redux notifications system
  • react-extras - Useful components and utilities for working with React
  • react-instantsearch - Lightning-fast search for React and React Native applications, by Algolia
  • uppy - The next open source file uploader for web browsers
  • react-motion - A spring that solves your animation problems
  • react-esi - React Edge Side Includes
  • hookstate - Modern, very fast and extendable state management for React that is based on hooks
  • universal-model-react - Unified state management solution for React
React Integration
React State Management
React AR and VR
  • React 360 - Create exciting 360 and VR experiences using React
  • Viro React - Platform for rapidly building AR/VR applications using React Native
React Renderers
Forms
  • React Forms
  • react-formal - Better form validation and value management for React, Provides minimal wiring
  • react-forms - Forms library for React
  • valuelink - Full-featured two-way data binding with extended React links
  • wingspan-forms - A dynamic form library for Facebook React
  • newforms - Isomorphic form-handling for React
  • formjs - A form generator for Reactjs
  • react-form-builder - A Form Builder for React.js
  • plexus-form - A dynamic form component for react using JSON-Schema
  • tcomb-form - UI library for developing forms writing less code
  • formsy-react - A form input builder and validator for React JS
  • Learn Raw React - Ridiculously Simple Forms
  • Winterfell - Generate complex, validated and extendable JSON-based forms in React
  • Redux-Autoform - Create Redux-Forms dynamically out of metadata
  • uniforms - Bunch of React components and helpers to easily generate and validate forms
  • formik - Forms in React, without tears
  • NeoForm - Modular HOCs for form state management and validation
  • react-jsonschema-form - A React component for building Web forms from JSON Schema
  • List View Select - A Toggleable select box for React Native with native components
  • Final Form 🏁 -
  • formland - A simple, super-flexible, extensible config based form generator
  • react-reactive-form - Angular like reactive forms in React
  • unform - ReactJS form library to create uncontrolled form structures with nested fields, validations and much more!
  • react-hook-form - Performant, flexible and extensible forms with easy to use validation
Autocomplete
Graphics
Data Managing
  • Immutable.js - Immutable Data Collections for Javascript
  • cortex - A javascript library for centrally managing data with React
  • avers - A modern client-side model abstraction library
  • imvvm - Immutable Model-View-ViewModel for React
  • morearty.js - Better state management for React in pure JavaScript
  • valuable - An immutable data store for React
  • react-resolver - Isomorphic library to recursively lazy-load data for React components
  • freezer-js - Lightweight and reactive immutable data structure for React
  • MobX - Simple, scalable state management
  • baobab - JavaScript persistent and optionally immutable data tree with cursors
  • baobab-react - React integration for Baobab
  • immstruct - Immutable data structures with history for top-to-bottom properties in component based libraries like React
  • seamless-immutable - Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects
  • tydel - Typed Models and Collections, with React bindings
  • extendable-immutable - Extend any Immutable.js data structure
  • statty - A tiny and unobtrusive state management library for React and Preact apps
  • Hydux - An Elm-Like state manager for React with "batteries included"
  • ReSub - A library for writing better React components and data stores
  • ProppyJS - A tiny library for functional props composition
  • WatermelonDB - 🍉 Next-gen database for powerful React and React Native apps that scales to 10, 000s of records and remains fast
  • RxDB - A realtime Database for JavaScript Applications
  • Effector - Fast and powerful reactive state manager. Lets you write simple, fast and type safe code and manage reactive state with ease.
  • reactn - React, but with built-in global state management
  • immer - Create the next immutable state by mutating the current one
Maps
Charts
  • DevExtreme React Chart - High-performance plugin-based React chart for Bootstrap and Material Design
  • react-chartjs - Common react charting components using chart.js
  • react-stockcharts - Highly customizable stock charts with ReactJS and d3
  • Number Picture - Low-level building blocks for constructing animated visualizations with React & D3.
  • Victory - A collection of composable React components for building interactive data visualizations
  • Recharts - A charting library built on D3 with an awesome declarative API
  • React-ApexCharts - React component for ApexCharts (An Interactive SVG Chart Library)
  • reaviz - React Data Visualization Library based on D3.js
  • react-vis - A React visualization library designed with the following principles in mind: React-friendly, high-level and customizable, expressive, and industry-strong.
  • nivo - It provides a rich set of data visualization components, built on top of the D3 and React libraries.
  • vx - A collection of reusable low-level visualization components. It combines the power of D3 to generate your visualization with the benefits of React for updating the DOM.
  • echarts-for-react - A very simple ECharts wrapper for React.
  • Chartify - React plugin for building charts using CSS.
  • Semiotic - A data visualization framework combining React and D3.
  • react-muze - React wrapper for muze (free data visualization library for creating exploratory data visualizations in browser, using WebAssembly)
  • reaflow - Diagram editor for React

React Native

Framework for building native apps using React

React Native General Resources

React Native Tutorials

React Native Development Tools

React Native Sample Apps

React Native Boilerplates

  • Create React Native App - Create a React Native app on any OS with no build config, with or without Expo
  • Snowflake - React Native iOS & Android with Redux, Parse.com, Jest (88% coverage)
  • Ignite - The hottest CLI for React Native, boilerplates, plugins, generators, and more!
  • React Native Starter Kit - A powerful starter project that bootstraps development of your mobile application

React Native Awesome Components

React Native Libraries

Redux

Predictable State Container for JavaScript Apps

Redux General Resources

Redux Tools

  • react-redux - Official React bindings for Redux
  • redux-devtools - DevTools for Redux with hot reloading, action replay, and customizable UI
  • react-router-redux - Bindings to keep react-router and redux in sync
  • redux-toolkit - The official, opinionated, batteries-included toolset for efficient Redux development
  • redux-form - A Higher Order Component using react-redux to keep form state
  • redux-thunk - Thunk middleware for redux
  • redux-logger - Logger middleware for redux
  • reselect - Selector library for Redux
  • normalizr - Normalizes nested JSON according to a schema
  • redux-saga - An alternative side effect model for Redux apps
  • redux-data-fx - Declarative Side Effects for Redux
  • redux-observable - RxJS middleware for Redux
  • redux-analytics - Analytics middleware for Redux
  • redux-undo - Higher order reducer to add undo/redo functionality to redux state containers
  • redux-search - Redux bindings for client-side search
  • redux-mock-store - A mock store for your testing your redux async action creators and middleware
  • redux-immutable - Create an equivalent function of Redux combineReducers that works with Immutable.js state
  • redux-react-i18n - An i18n solution for redux/react
  • R16N - A redux/react I18n solution
  • redux-actiontyper - Helper to create less verbose action types for Redux
  • redux-state-validator - A simple redux middleware to validate redux state values and object types using JSON Schema
  • redux-persist - Persist and rehydrate a redux store

Redux Tutorials


MobX

Simple, scalable state management for JavaScript Apps

MobX General Resources

MobX Tools

  • mobx-react - React component wrapper for combining React with MobX

MobX Tutorials


GraphQL

Query Language

GraphQL Spec

GraphQL Tools

GraphQL Tutorials

GraphQL Implementations

Server Integration

Database Integration

  • Hasura - Instant Realtime GraphQL on Postgres
  • Prisma - A performant open-source GraphQL ORM-like * layer doing the heavy lifting in your GraphQL server.
  • graphql-bookshelf - Some help defining GraphQL schema around BookshelfJS models
  • GraphpostgresQL - GraphQL for PostgreSQL
  • graffiti - Node.js GraphQL ORM
  • sql-to-graphql - Generate a GraphQL API based on your SQL database structure
  • graphql-sequelize - GraphQL & Relay for MySQL & Postgres via Sequelize

Relay

Data-Driven React Applications

Relay General Resources

Relay Tutorials

Relay Tools


Apollo

Data stack based on GraphQL

Apollo General Resources

Apollo Tools


Videos

Important Talks

Video Tutorials


Demo React Apps


Real React Apps

  • kibana - Your window into the Elastic Stack
  • firefox debugger - The Firefox debugger that works anywhere
  • spectrum – Simple, powerful online communities
  • mattermost - Open source Slack alternative
  • overreacted - Personal blog by Dan Abramov
  • winamp2-js - Winamp 2 reimplemented for the browser
  • dnote - A command line notebook with multi-device sync and web interface
<iframe src="https://glitch.com/embed/#!/embed/scrawny-coordinated-headlight?path=views/index.html&previewSize=100" title="scrawny-coordinated-headlight on Glitch" allow="geolocation; microphone; camera; midi; vr; encrypted-media" style="height: 100%; width: 100%; border: 0;"> </iframe>

About


Languages

Language:JavaScript 68.8%Language:TypeScript 18.4%Language:CSS 5.7%Language:HTML 5.1%Language:SCSS 1.0%Language:Shell 0.9%Language:Less 0.1%Language:Dockerfile 0.1%Language:AppleScript 0.1%Language:Sass 0.0%