Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
React useCallback x function
(version: 0)
Comparing performance of:
ComponentWithOuterFunctionUseCallback vs ComponentWithUseCallback vs ComponentWithInlineFunction vs ComponentWithArrowFunction
Created:
3 years 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/16.13.1/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.1/umd/react-dom.production.min.js"></script> <div id="root"></div> </body> </html>
Script Preparation code:
function ComponentWithOuterFunctionUseCallback() { function functionToTest() { return undefined; } const testFunction = React.useCallback(functionToTest, []); return React.createElement('button', {onClick: testFunction}, 'Test click'); } function ComponentWithUseCallback() { const testFunction = React.useCallback(() => undefined, []); return React.createElement('button', {onClick: testFunction}, 'Test click'); } function ComponentWithInlineFunction() { function testFunction() { return undefined; } return React.createElement('button', {onClick: testFunction}, 'Test click'); } function ComponentWithArrowFunction() { const testFunction = () => { return undefined; } return React.createElement('button', {onClick: testFunction}, 'Test click'); }
Tests:
ComponentWithOuterFunctionUseCallback
ReactDOM.render(React.createElement(ComponentWithOuterFunctionUseCallback), document.getElementById('root'))
ComponentWithUseCallback
ReactDOM.render(React.createElement(ComponentWithUseCallback), document.getElementById('root'))
ComponentWithInlineFunction
ReactDOM.render(React.createElement(ComponentWithInlineFunction), document.getElementById('root'))
ComponentWithArrowFunction
ReactDOM.render(React.createElement(ComponentWithArrowFunction), document.getElementById('root'))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
ComponentWithOuterFunctionUseCallback
ComponentWithUseCallback
ComponentWithInlineFunction
ComponentWithArrowFunction
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
React useCallback hook vs. function
React useCallback hook vs. function (React 18)
React 18.2 useCallback hook vs. function
React useCallback hook vs. function 18
Comments
Confirm delete:
Do you really want to delete benchmark?