Skip to content

NumberTicker and ts strict mode #860

@manjime83

Description

@manjime83

Describe the bug

The useEffect in /docs/components/number-ticker throws a TypeScript/ESLint error: "Not all code paths return a value". This occurs because the cleanup function (return () => clearTimeout(timer)) only executes inside the if (isInView) block, leaving the else path without an explicit return.

Affected component/components

NumberTicker

How to reproduce

Current code:
useEffect(() => {
if (isInView) {
const timer = setTimeout(() => {
motionValue.set(direction === "down" ? startValue : value);
}, delay * 1000);
return () => clearTimeout(timer); // Linter flags: not all paths return value
}
// No return here triggers ESLint consistent-return rule violation
}, [motionValue, isInView, delay, value, direction, startValue]);

The useEffect should pass linting while maintaining identical runtime behavior—skip animation setup when !isInView, and provide cleanup for the timer when applicable.

Codesandbox/StackBlitz link

No response

Logs

System Info

- React version: [18.x]
- TypeScript: enabled with strict mode
- ESLint: consistent-return rule active
- Reproduction: Create new MagicUI project, enable TS/ESLint, use NumberTicker component

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions