An open API service indexing awesome lists of open source software.

https://github.com/hellsan631/stress-hooks

An app to benchmark React Hooks
https://github.com/hellsan631/stress-hooks

Last synced: 4 months ago
JSON representation

An app to benchmark React Hooks

Awesome Lists containing this project

README

          

# Stress Testing React Hooks

[Stress Testing React Hooks](https://www.matthiasjenny.com/stress-hooks/) is a benchmark tool for [React Hooks](https://reactjs.org/docs/hooks-intro.html).

## Overview

Users can benchmark the following six components with a benchmark function of their choice:

### `ClassComponent`

```jsx
class ClassComponent extends React.Component {
constructor(props) {
super(props);
const { benchmark, args } = this.props;
this.state = { result: benchmark(...args) };
}

render() {
return (
<>

ClassComponent



Result: {this.state.result}


Render #: {this.props.renderNumber}



>
);
}
}
```

### `FunctionalComponent`

```jsx
function FunctionalComponent(props) {
const { benchmark, args } = props;
const result = benchmark(...args);

return (
<>

FunctionalComponent



Result: {result}


Render #: {props.renderNumber}



>
);
}
```

### `HooksComponent`

```jsx
function NaiveHooksComponent(props) {
const { benchmark, args } = props;
const [result] = useState(benchmark(...args));
return (
<>

HooksComponent



Result: {result}


Render #: {props.renderNumber}



>
);
}
```

### `MemoHooksComponent`

```jsx
function MemoHooksComponent(props) {
const { benchmark, args } = props;
const calculatedResult = useMemo(() => benchmark(...args), props.args);
const [result] = useState(calculatedResult);
return (
<>

MemoHooksComponent



Result: {result}


Render #: {props.renderNumber}



>
);
}
```

### `FunctionHooksComponent`

```jsx
function FunctionHooksComponent(props) {
const { benchmark, args } = props;
const [result] = useState(() => benchmark(...args));
return (
<>

FunctionHooksComponent



Result: {result}


Render #: {props.renderNumber}



>
);
}
```

### `RefHooksComponent`

```jsx
function RefHooksComponent(props) {
const { benchmark, args } = props;
const ref = useRef(null);
if (ref.current === null) {
ref.current = benchmark(...args);
}
const [result] = useState(ref.current);
return (
<>

RefHooksComponent



Result: {result}


Render #: {props.renderNumber}



>
);
}
```

## [Contributing](./CONTRIBUTING.md)

## [License](./LICENSE)