MCPcopy
hub / github.com/infernojs/inferno

github.com/infernojs/inferno @v9.1.0 sqlite

repository ↗ · DeepWiki ↗ · release v9.1.0 ↗
3,911 symbols 8,531 edges 346 files 10 documented · 0%
README

Inferno

Build Status Coverage Status MIT NPM npm downloads Discord gzip size Backers on Open Collective Sponsors on Open Collective

Inferno is an insanely fast, React-like library for building high-performance user interfaces on both the client and server.

Description

The main objective of the InfernoJS project is to provide the fastest possible runtime performance for web applications. Inferno excels at rendering real time data views or large DOM trees.

The performance is achieved through multiple optimizations, for example:

  • Inferno's own JSX compilers creates monomorphic createVNode calls, instead of createElement calls. Optimizing runtime performance of the application.
  • SWC plugin inferno is a plugin for SWC. It can compile TSX and JSX
  • Babel plugin inferno is a plugin for BabelJs. It can compile JSX.
  • TS plugin inferno is a plugin for TSC. It can compile TSX.
  • Inferno's diff process uses bitwise flags to memoize the shape of objects
  • Child nodes are normalized only when needed
  • Special JSX flags can be used during compile time to optimize runtime performance at application level
  • Many micro optimizations

Features

  • Component driven + one-way data flow architecture
  • React-like API, concepts and component lifecycle events
  • Partial synthetic event system, normalizing events for better cross browser support
  • Inferno's linkEvent feature removes the need to use arrow functions or binding event callbacks
  • Isomorphic rendering on both client and server with inferno-server
  • Unlike React and Preact, Inferno has lifecycle events on functional components
  • Unlike Preact and other React-like libraries, Inferno has controlled components for input/select/textarea elements
  • Components can be rendered outside their current html hierarchy using createPortal - API
  • Support for older browsers without any polyfills
  • defaultHooks for Functional components, this way re-defining lifecycle events per usage can be avoided
  • Inferno supports setting styles using string `

or using object literal syntax

. For camelCase syntax support see [inferno-compat`](https://github.com/infernojs/inferno/tree/master/packages/inferno-compat). - Fragments (v6) - createRef and forwardRef APIs (v6) - componentDidAppear, componentWillDisappear and componentWillMove (v8) - class and function component callbacks to ease animation work, see inferno-animation package

Runtime requirements

Inferno v9 requires following features to be present in the executing runtime:

  • Promise
  • String.prototype.includes()
  • String.prototype.startsWith()
  • Array.prototype.includes()
  • Object.spread()
  • for ... of

Browser support

Since version 4 we have started running our test suite without any polyfills. Inferno is now part of Saucelabs open source program and we use their service for executing the tests.

InfernoJS is actively tested with browsers listed below, however it may run well on older browsers as well. This is due to limited support of browser versions in recent testing frameworks. https://github.com/jasmine/jasmine/blob/main/release_notes/5.0.0.md

Browser Test Status

Migration guides

Benchmarks

Live examples at https://infernojs.github.io/inferno

Code Example

Let's start with some code. As you can see, Inferno intentionally keeps the same design ideas as React regarding components: one-way data flow and separation of concerns.

In these examples, JSX is used via the Inferno JSX Babel Plugin to provide a simple way to express Inferno virtual DOM. You do not need to use JSX, it's completely optional, you can use hyperscript or createElement (like React does). Keep in mind that compile time optimizations are available only for JSX.

import { render } from 'inferno';

const message = "Hello world";

render(
  <MyComponent message={ message } />,
  document.getElementById("app")
);

Furthermore, Inferno also uses ES6 components like React:

import { render, Component } from 'inferno';

class MyComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      counter: 0
    };
  }
  render() {
    return (



        <h1>Header!</h1>
        <span>Counter is at: { this.state.counter }</span>



    );
  }
}

render(
  <MyComponent />,
  document.getElementById("app")
);

Because performance is an important aspect of this library, we want to show you how to optimize your application even further. In the example below we optimize diffing process by using JSX $HasVNodeChildren and $HasTextChildren to predefine children shape compile time. In the MyComponent render method there is a div that contains JSX expression node as its content. Due to dynamic nature of Javascript that variable node could be anything and Inferno needs to go through the normalization process to make sure there are no nested arrays or other invalid data. Inferno offers a feature called ChildFlags for application developers to pre-define the shape of vNode's child node. In this example case it is using $HasVNodeChildren to tell the JSX compiler, that this vNode contains only single element or component vNode. Now inferno will not go into the normalization process runtime, but trusts the developer decision about the shape of the object and correctness of data. If this contract is not kept and node variable contains invalid value for the pre-defined shape (fe. null), then application would crash runtime. There is also span-element in the same render method, which content is set dynamically through _getText() method. There $HasTextChildren child-flag fits nicely, because the content of that given "span" is never anything else than text. All the available child flags are documented here.

import { createTextVNode, render, Component } from 'inferno';

class MyComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      counter: 0
    };
  }

  _getText() {
     return 'Hello!';
  }

  render() {
    const node = this.state.counter > 0 ? 

0

 : <span $HasTextChildren>{this._getText()}</span>;

    return (



        <h1>Header!</h1>


{node}





    );
  }
}

render(
  <MyComponent />,
  document.getElementById("app")
);

Tear down

To tear down inferno application you need to render null on root element. Rendering null will trigger unmount lifecycle hooks for whole vDOM tree and remove global event listeners. It is important to unmount unused vNode trees to free browser memory.

import { createTextVNode, render, Component } from 'inferno';

const rootElement = document.getElementById("app");

// Start the application
render(
  <ExampleComponent/>,
  rootElement
);

// Tear down
render(
  null,
  rootElement
);

More Examples

If you have built something using Inferno you can add them here:

Getting Started

The easiest way to get started with Inferno is by using Create Inferno App.

Alternatively, you can try any of the following: * the Inferno Boilerplate for a very simple setup. * for a more advanced example demonstrating how Inferno might be used, we recommend trying out Inferno Starter Project by nightwolfz. * for using Inferno to build a mobile app, try Inferno Mobile Starter Project by Rudy-Zidan. * for TypeScript support and bundling, check out ts-plugin-inferno, or inferno-typescript-example. * for an example of how to use Inferno in codesandbox: https://codesandbox.io/s/znmyj24w4p * for using parcel and typescript

Core package:

npm install --save inferno

Addons:

# server-side rendering
npm install --save inferno-server
# routing
npm install --save inferno-router

Pre-bundled files for browser consumption can be found on our cdnjs:

Or on jsDelivr:

https://cdn.jsdelivr.net/npm/inferno@latest/dist/inferno.min.js

Or on unpkg.com:

https://unpkg.com/inferno@latest/dist/inferno.min.js

Creating Virtual DOM

JSX:

npm install --save-dev babel-plugin-inferno

Hyperscript:

npm install --save inferno-hyperscript

createElement:

npm install --save inferno-create-element

Compatibility with existing React apps

npm install --save-dev inferno-compat

Note: Make sure you read more about inferno-compat before using it.

Third-party state libraries

Inferno now has bindings available for some of the major state management libraries out there:

JSX

Inferno has its own JSX Babel plugin.

Differences from React

  • Inferno doesn't have a fully synthetic event system like React does. Inferno has a partially synthetic event system, instead opting to only delegate certain events (such as onClick).
  • Inferno doesn't support React Native. Inferno was only designed for the browser/server with the DOM in mind.
  • Inferno doesn't support legacy string refs, use createRef or callback ref API
  • Inferno provides lifecycle events on functional components. This is a major win for people who prefer lightweight components rather than ES2015 classes.

Differences from Preact

  • Inferno has a partial synthetic event system, resulting in better performance via delegation of certain events.
  • Inferno is much faster than Preact in rendering, updat

Extension points exported contracts — how you extend this code

ChildContextProvider (Interface)
(no doc) [28 implementers]
packages/inferno/src/core/types.ts
RouteState (Interface)
* The public API for matching a single path and rendering.
packages/inferno-router/src/Route.ts
FragmenterProps (Interface)
(no doc)
packages/inferno-hydrate/__tests__/hydrate.spec.tsx
InnerProps (Interface)
(no doc)
packages/inferno-create-element/__tests__/components1.spec.tsx
FoobarState (Interface)
(no doc)
packages/inferno-server/__tests__/creation-stream.spec.server.tsx
Props (Interface)
(no doc)
packages/inferno-redux/src/components/Provider.ts
InfernoSnapshot (Interface)
(no doc)
packages/inferno-test-utils/src/jest.ts
Event (Interface)
(no doc)
packages/inferno-compat/src/index.ts

Core symbols most depended-on inside this repo

createElement
called by 1629
packages/inferno-create-element/src/index.ts
render
called by 1582
packages/inferno-compat/src/index.ts
setState
called by 334
packages/inferno/src/core/types.ts
testCase
called by 174
scripts/fakedom/libs/uibench.js
scuClone
called by 174
scripts/fakedom/libs/uibench.js
testCase
called by 174
docs/uibench/custom-uibench.js
scuClone
called by 174
docs/uibench/custom-uibench.js
render
called by 157
packages/inferno-router/src/withRouter.ts

Shape

Method 1,329
Function 1,219
Class 1,060
Interface 300
Enum 3

Languages

TypeScript100%

Modules by API surface

packages/inferno-redux/__tests__/components/connect.spec.js138 symbols
packages/inferno/src/core/types.ts125 symbols
packages/inferno-create-element/__tests__/components2b.spec.tsx122 symbols
packages/inferno/__tests__/newlifecycle.spec.tsx119 symbols
browser/inferno.babel.umd.6.6.0.min.js107 symbols
packages/inferno-create-element/__tests__/components.spec.ts90 symbols
packages/inferno/__tests__/children.spec.tsx87 symbols
packages/inferno/__tests__/hooks.spec.tsx75 symbols
packages/inferno/__tests__/setState.spec.tsx74 symbols
packages/inferno-create-element/__tests__/components3.spec.tsx74 symbols
packages/inferno-create-element/__tests__/components1.spec.tsx60 symbols
packages/inferno-create-element/__tests__/update.spec.jsx53 symbols

Dependencies from manifests, versioned

@babel/core7.29.0 · 1×
@babel/plugin-proposal-class-properties7.18.6 · 1×
@babel/plugin-transform-modules-commonjs7.28.6 · 1×
@babel/preset-env7.29.2 · 1×
@babel/preset-typescript7.28.5 · 1×
@eslint/js10.0.1 · 1×
@parcel/config-default2.13.2 · 1×
@parcel/packager-ts2.13.2 · 1×
@parcel/transformer-babel2.13.2 · 1×
@parcel/transformer-sass2.13.2 · 1×
@parcel/transformer-typescript-types2.13.2 · 1×
@rollup/plugin-alias6.0.0 · 1×

For agents

$ claude mcp add inferno \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact