### Install Million.js via CLI (bun)
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/install.fr-FR.mdx
Use the bunx command for installation.
```bash
bunx million@latest
```
--------------------------------
### Install Million.js Manually (bun)
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/install.fr-FR.mdx
Install the Million.js package using bun.
```bash
bun add million
```
--------------------------------
### Install Million.js CLI
Source: https://github.com/aidenybai/million/blob/main/README.md
Use the Million.js CLI to automatically install the package and configure your project. After installation, running your project will display information in the command line.
```bash
npx million@latest
```
--------------------------------
### Install Million.js via CLI (yarn)
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/install.fr-FR.mdx
Use the yarn add command for installation.
```bash
yarn add million@latest
```
--------------------------------
### Install Million.js via CLI (pnpm)
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/install.fr-FR.mdx
Use the pnpx command for installation with pnpm.
```bash
pnpx million@latest
```
--------------------------------
### Install Million.js Manually (yarn)
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/install.fr-FR.mdx
Install the Million.js package using yarn.
```bash
yarn add million
```
--------------------------------
### Install project dependencies
Source: https://github.com/aidenybai/million/blob/main/packages/kitchen-sink/README.md
Install required packages using pnpm.
```bash
pnpm install
```
--------------------------------
### Run the development server
Source: https://github.com/aidenybai/million/blob/main/packages/kitchen-sink/README.md
Start the local development server for the Kitchen Sink application.
```bash
pnpm dev
```
--------------------------------
### Install TanStack Virtual
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/manual-mode/virtualization.zh-CN.mdx
Install the beta version of TanStack React Virtual using your preferred package manager.
```bash
npm install @tanstack/react-virtual@beta
```
```bash
pnpm install @tanstack/react-virtual@beta
```
```bash
yarn add @tanstack/react-virtual@beta
```
```bash
bun add @tanstack/react-virtual@beta
```
--------------------------------
### Install Million.js Manually (pnpm)
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/install.fr-FR.mdx
Install the Million.js package using pnpm.
```bash
pnpm install million
```
--------------------------------
### Install Million Lint Package
Source: https://github.com/aidenybai/million/blob/main/website/pages/blog/lint.en-US.mdx
Manual installation commands for various package managers.
```bash
npm install @million/lint@latest
```
```bash
pnpm install @million/lint@latest
```
```bash
yarn add @million/lint@latest
```
```bash
bun add @million/lint@latest
```
--------------------------------
### Install Million.js via CLI
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/index.zh-CN.mdx
Commands to initialize Million.js in a project using various package managers.
```bash
npx million@latest
```
```bash
pnpx million@latest
```
```bash
yarn add million@latest
```
```bash
bunx million@latest
```
--------------------------------
### Million.js Combined Block Example
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/manual-mode/manual-mode.en-US.mdx
Demonstrates how Million.js blocks can be used for efficient rendering, especially with dynamic data. This example shows a combined approach.
```jsx
import { block } from "million/react";
const CombinedBlockExample = block(() => (
Hello world
This is a paragraph.
));
```
--------------------------------
### Install Million.js
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/install.en-US.mdx
Use a package manager to add the Million.js dependency to your project.
```bash
npm install million
```
```bash
pnpm install million
```
```bash
yarn add million
```
```bash
bun add million
```
--------------------------------
### React Virtual DOM Example
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/manual-mode/manual-mode.zh-CN.mdx
This example demonstrates the standard virtual DOM rendering approach in React. It is provided for comparison with Million.js block rendering.
```jsx
function VDomExample() {
return (
Item 1
Item 2
Item 3
);
}
```
--------------------------------
### React Virtual DOM Example
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/manual-mode/manual-mode.en-US.mdx
Illustrates the traditional React virtual DOM rendering process. This is shown for comparison with Million.js.
```jsx
function VDomExample() {
return (
Hello world
This is a paragraph.
);
}
```
--------------------------------
### Full Optimized Million.js Implementation
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/manual-mode/manual-mode.zh-CN.mdx
A complete example integrating block and For to achieve high-performance rendering.
```jsx
import { useState } from 'react';
import { Table, Input, lotsOfElements } from './ui';
import { buildData } from './data';
import { block, For } from 'million/react';
const RowBlock = block(
function Row({ adjective, color, noun }) {
return (
{adjective}
{color}
{noun}
{...lotsOfElements}
);
}
);
function App() {
const [rows, setRows] = useState(1);
const data = buildData(rows);
return (
{({ adjective, color, noun }) => (
)}
);
}
export default App;
```
--------------------------------
### Million.js Combined Block Example
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/manual-mode/manual-mode.zh-CN.mdx
This example showcases how to use Million.js blocks for efficient rendering, particularly for lists and nested data. It highlights performance gains by optimizing tree traversal.
```jsx
import { block } from 'million/react';
const MyComponent = block(() => {
return (
Item 1
Item 2
Item 3
);
});
```
--------------------------------
### Block Virtual DOM: Data vs. DOM Nodes Example
Source: https://github.com/aidenybai/million/blob/main/website/pages/blog/virtual-dom.en-US.mdx
An example highlighting a situation where the Block Virtual DOM might be less effective because the number of data values to diff exceeds the number of virtual DOM nodes.
```jsx
// 5 data values to diff
function Component({ a, b, c, d, e }) {
// 1 virtual DOM node to diff
return
{a + b + c + d + e}
;
}
```
--------------------------------
### Install Million.js via package manager
Source: https://github.com/aidenybai/million/blob/main/website/pages/blog/million-v2.5.1.en-US.mdx
Commands to upgrade to the latest version of Million.js using common package managers.
```bash
npm install million@latest
```
```bash
pnpm install million@latest
```
```bash
yarn add million@latest
```
--------------------------------
### Configure Create React App with Craco and Million.js
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/install.fr-FR.mdx
Set up Million.js for Create React App by configuring Craco and adding the webpack plugin. Requires Craco installation.
```javascript
const million = require("million/compiler");
module.exports = {
webpack: {
plugins: { add: [million.webpack({ auto: true })] },
},
};
```
--------------------------------
### Complete Data Grid Example
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/manual-mode/manual-mode.zh-CN.mdx
A full implementation of a data grid component in React, demonstrating efficient rendering of dynamic data. It includes state management for rows, data generation, and table rendering using `Array.map`.
```jsx
import { useState } from 'react';
import { Table, Input } from './ui';
import { buildData } from './data';
function App() {
const [rows, setRows] = useState(1);
const data = buildData(rows);
return (
{data.map(({ adjective, color, noun }) => (
{adjective}
{color}
{noun}
))}
);
}
export default App;
```
--------------------------------
### Example Telemetry Event
Source: https://github.com/aidenybai/million/blob/main/website/pages/telemetry.en-US.mdx
This is an example of an anonymous telemetry event that might be collected. It includes the event type and a payload with framework information.
```json
{
"event": "compile",
"payload": {
"framework": "vite"
}
}
```
--------------------------------
### React Dynamic Component Example
Source: https://github.com/aidenybai/million/blob/main/website/pages/blog/million-beyond-speed.en-US.mdx
This component fetches stock trade data every second and dynamically renders BuyComponent or SellComponent based on the trade type. It's an example of a highly dynamic component not suited for Million.js.
```jsx
import { useState, useEffect } from "react";
import { BuyComponent, SellComponent } from "@/components/recent-trades"
export function RecentTrades() {
const [trades, setTrades] = useState([]);
useEffect(() => {
// set a timer to make this event run every second
const tradeTimer = setInterval(() => {
let tradeRes = fetch("example.com/stocks/trades");
// errors? never heard of them
tradeRes = JSON.parse(tradeRes);
setTrades(previousList => {
// remove the amount of elements returned from
// our fetch call to stay at 1,000 elements
previousList.slice(0, tradeRes.length);
// add the most recent elements
for (i, i < tradeRes.length, i++) {
previousList.push(tradeRes[i]);
};
return previousList;
});
}, 1000);
return () => clearInterval(tradeTimer);
}, [])
return (
)
}
```
--------------------------------
### Example React Component
Source: https://github.com/aidenybai/million/blob/main/README.md
A simple React component demonstrating state management with `useState` and an event handler for a button click. This component is used to illustrate React's rendering and reconciliation process.
```jsx
function App() {
const [count, setCount] = useState(0);
const increment = () => setCount(count + 1);
return (
Count: {count}
);
}
```
--------------------------------
### Block Virtual DOM: Static Content Example
Source: https://github.com/aidenybai/million/blob/main/website/pages/blog/virtual-dom.en-US.mdx
Illustrates a scenario where the Block Virtual DOM is beneficial due to a large amount of static content surrounding dynamic elements.
```jsx
{dynamic}
Lots and lots of static content...
```
--------------------------------
### Pure React Rendering of Many Elements
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/manual-mode/manual-mode.en-US.mdx
This example shows a typical React implementation for rendering a large number of elements within a table. It demonstrates how React can struggle with performance when dealing with a high volume of DOM nodes. Use this to observe the performance bottleneck before applying optimizations.
```jsx
import { useState } from 'react';
import { Table, Input, lotsOfElements } from './ui';
import { buildData } from './data';
function App() {
const [rows, setRows] = useState(1);
const data = buildData(rows);
return (
{data.map(({ adjective, color, noun }) => (
{adjective}
{color}
{noun}
{...lotsOfElements}
))}
);
}
export default App;
```
--------------------------------
### Next.js Server-Side Props Example
Source: https://github.com/aidenybai/million/blob/main/website/pages/wrapped/[id].mdx
Demonstrates how to use getServerSideProps in Next.js to fetch data on the server. This function is called on each request to the page.
```javascript
import Wrapped from '../../components/wrapped';
import { useData } from 'nextra/data';
export const getServerSideProps = (params) => {
return { props: { ssg: { id: params.query.id } } };
};
export const Parent = () => {
const data = useData();
return ;
};
```
--------------------------------
### Define a React component structure
Source: https://github.com/aidenybai/million/blob/main/website/pages/blog/virtual-dom.en-US.mdx
A basic React component example used to illustrate the tree structure processed during virtual DOM diffing.
```jsx
function Numbers() {
return (
);
}
```
--------------------------------
### Optimized React Table Rendering with Million.js
Source: https://github.com/aidenybai/million/blob/main/website/pages/docs/manual-mode/manual-mode.en-US.mdx
This example integrates Million.js's `block` and `For` components into a React application to render a large list of table rows efficiently. It demonstrates the performance improvement compared to a pure React approach, especially noticeable when interacting with the input to change the number of rows.
```jsx
import { useState } from 'react';
import { Table, Input, lotsOfElements } from './ui';
import { buildData } from './data';
import { block, For } from 'million/react';
const RowBlock = block(
function Row({ adjective, color, noun }) {
return (
{adjective}
{color}
{noun}
{...lotsOfElements}
);
}
);
function App() {
const [rows, setRows] = useState(1);
const data = buildData(rows);
return (
{({ adjective, color, noun }) => (
)}
);
}
export default App;
```
--------------------------------
### Block Virtual DOM: Dynamic Content Example
Source: https://github.com/aidenybai/million/blob/main/website/pages/blog/virtual-dom.en-US.mdx
Shows a case where the Block Virtual DOM might not offer significant advantages over a regular Virtual DOM due to a high proportion of dynamic content.
```jsx
{dynamic}
{dynamic}
{dynamic}
{dynamic}
{dynamic}
```
--------------------------------
### Million.js Counter Example
Source: https://github.com/aidenybai/million/blob/main/website/pages/blog/virtual-dom.en-US.mdx
A simple counter component implemented with Million.js' block function. This demonstrates how dynamic parts of the UI are handled.
```jsx
import { useState } from 'react';
import { block } from 'million/react';
function Count() {
const [count, setCount] = useState(0);
const node1 = count + 1;
const node2 = count + 2;
return (
{node1}
{node2}
);
}
const CountBlock = block(Count);
```
--------------------------------
### React Reconciliation Diff Example
Source: https://github.com/aidenybai/million/blob/main/README.md
Shows the difference between two snapshots of a React component during the reconciliation process. This highlights the specific DOM nodes that need updating.
```diff
-
Count: 0
+
Count: 1
```
--------------------------------
### Initialize Million Lint via CLI
Source: https://github.com/aidenybai/million/blob/main/website/pages/blog/lint.en-US.mdx
Run this command in any existing React project to automatically set up Million Lint.
```bash
npx @million/lint@latest
```
--------------------------------
### Navigate to the Kitchen Sink directory
Source: https://github.com/aidenybai/million/blob/main/packages/kitchen-sink/README.md
Change the working directory to the kitchen-sink package folder.
```bash
cd packages/kitchen-sink
```
--------------------------------
### Conceptual Million.js Reconciler Example
Source: https://github.com/aidenybai/million/blob/main/README.md
Illustrates how Million.js directly updates DOM nodes when state changes, bypassing traditional diffing. This example shows a simplified view of the compiler's output for state updates.
```jsx
function App() {
const [count, setCount] = useState(0);
const increment = () => setCount(count + 1);
// generated by compiler
if (count !== prevCount) {