Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
useCallback hook vs inline function in React 18
(version: 1)
Comparing performance of:
Inline vs Hooks
Created:
one year ago
by:
Guest
Go to the latest result
HTML Preparation code:
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script> <script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script> <div id="root"></div>
Script Preparation code:
function ComponentWithInlineFunction() { const clickMe = evt => evt.preventDefault(); return React.createElement('button', {onClick: clickMe}, 'Click me!'); } function ComponentWithUseCallback() { const clickMe = React.useCallback(evt => evt.preventDefault(), []); return React.createElement('button', {onClick: clickMe}, 'Click me!'); }
Tests:
Inline
ReactDOM.render(React.createElement(ComponentWithInlineFunction), document.getElementById('root'))
Hooks
ReactDOM.render(React.createElement(ComponentWithUseCallback), document.getElementById('root'))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Inline
Hooks
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 Edg/146.0.0.0
Browser/OS:
Chrome 146 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Hooks
43K/s
Inline
34K/s
View exact numbers
Test name
Executions per second
✓
Hooks
43,187 Ops/sec
Inline
34,446 Ops/sec
Related benchmarks
React Hooks vs. Inline
React Hooks vs. Inline 2
React useCallback hook vs inline function
React useCallback hook vs. function in 18 react
React useCallback vs inline function vs inline handler
React useCallback hook vs. function 18
With or without useMemo
Comments
Confirm delete:
Do you really want to delete benchmark?