Packages@accelint/coreUtility
noop
No-operation function that does nothing
Usage
import { noop } from '@accelint/core';
// Does nothing
noop();
// Accepts any argument but ignores it
noop('ignored');
noop(42);
noop({ data: 'also ignored' });Reference
function noop(_x?: unknown): voidParameters
| Parameter | Type | Description |
|---|---|---|
_x | unknown | undefined | Optional parameter that is ignored |
Returns
Returns void (nothing).
Examples
Example: Placeholder callback
import { noop } from '@accelint/core';
function fetchData(
url: string,
onSuccess: (data: unknown) => void = noop,
onError: (error: Error) => void = noop
) {
fetch(url)
.then(onSuccess)
.catch(onError);
}
// Use without callbacks
fetchData('https://api.example.com/data');Example: Disabling logging
import { noop } from '@accelint/core';
const logger = process.env.NODE_ENV === 'production'
? noop
: console.log;
logger('Debug message'); // Logged in dev, silent in prodExample: Optional event handlers
import { noop } from '@accelint/core';
interface ButtonProps {
onClick?: () => void;
onHover?: () => void;
}
function Button({ onClick = noop, onHover = noop }: ButtonProps) {
return (
<button
onClick={onClick}
onMouseEnter={onHover}
>
Click Me
</button>
);
}Example: Testing with stubbed functions
import { noop } from '@accelint/core';
function processData(
data: unknown[],
onProgress: (percent: number) => void = noop
) {
for (let i = 0; i < data.length; i++) {
// Process data...
onProgress((i / data.length) * 100);
}
}
// Test without progress callback
processData([1, 2, 3]); // No errors, progress updates ignoredExample: Conditional operations
import { noop } from '@accelint/core';
const debug = process.env.DEBUG === 'true'
? console.log.bind(console)
: noop;
debug('This appears only when DEBUG=true');Good to know:
noopis useful as a default value for optional callback parameters, allowing callers to omit callbacks without requiringundefinedchecks. It's also commonly used to disable logging or other side effects in production builds.