Skip to content

'can't access lexical declaration 'value' before initialization' error when using custom formatter #233

Description

@danaYatsuta

Hello, thanks for the package!

I have the following code to show "just now" instead of "n seconds ago":

function timeAgoFormatter(
  _value: number,
  unit: string,
  _suffix: string,
  _epochMilliseconds: number,
  nextFormatter: () => React.ReactNode,
) {
  if (unit === "second") return "just now";
  return nextFormatter();
}

...

<TimeAgo
  date={initialDate}
  formatter={timeAgoFormatter}
/>

It works fine, but, if initialDate is the current time, after a minute passes, I get the following error:

## Error Type
Console ReferenceError

## Error Message
can't access lexical declaration 'value' before initialization


    at timeAgoFormatter (app/components/comment.tsx:108:10)
    at renderer_attach/p.scheduleRefresh (<anonymous code>:1:88621)
    at <unknown> (app/components/comment.tsx:109:1)
    at Comment (app/components/comment.tsx:55:11)
    at <anonymous> (app/page.tsx:7:7)
    at Array.map (<anonymous>:1:18)
    at Home (app/page.tsx:5:42)

## Code Frame
  106 | ) {
  107 |   if (unit === "second") return "just now";
> 108 |   return nextFormatter();
      |          ^
  109 | }
  110 |

Next.js version: 16.0.3 (Turbopack)

The time keeps rendering correctly, but still, this error is concerning me. Am I doing something wrong, or is this a bug?

Package version: 8.3.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions