Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
React useCallback hook vs. custom hook (React 18)
(version: 1)
Comparing performance of:
ComponentWithOuterFunctionUseCallback vs ComponentWithUseCallback
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script> <div id="root"></div> </body> </html>
Script Preparation code:
const useHandler = (handler) => React.useRef(handler).current; function useHandlerComponent() { const testFunction = useHandler(evt => evt.preventDefault(), []); return React.createElement('button', { onClick: testFunction }, 'Test click'); } function UseCallbackComponent() { const testFunction = React.useCallback(evt => evt.preventDefault(), []); return React.createElement('button', { onClick: testFunction }, 'Test click'); }
Tests:
ComponentWithOuterFunctionUseCallback
ReactDOM.render(React.createElement(useHandlerComponent), document.getElementById('root'))
ComponentWithUseCallback
ReactDOM.render(React.createElement(UseCallbackComponent), document.getElementById('root'))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
ComponentWithOuterFunctionUseCallback
ComponentWithUseCallback
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
ComponentWithOuterFunctionUseCallback
1005868.0 Ops/sec
ComponentWithUseCallback
993201.9 Ops/sec
Related benchmarks:
React useCallback hook vs. function
React useCallback hook vs. function in 18 react
React useCallback hook vs. function (React 18)
React 18.2 useCallback hook vs. function
React useCallback hook vs. function vs. external
React useCallback hook vs. function 18
React useCallback hook vs. function 2
useCallback vs without
React 18 useCallback hook vs. function
Comments
Confirm delete:
Do you really want to delete benchmark?