Skip to content

Commit

Permalink
use React.createElement instead of jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle committed Feb 23, 2024
1 parent f3b7276 commit 35212f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Support old versions of react (pre v16.14)

## 2.0.0 (2024-02-09)

- 💥 BREAKING CHANGE: Enable `hideSeconds` by default
Expand Down
30 changes: 18 additions & 12 deletions src/index.tsx → src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { memo, useCallback, useEffect, useMemo, useState } from "react";
import {
createElement,
memo,
useCallback,
useEffect,
useMemo,
useState,
} from "react";

// all JS environments that support the Intl API guarantee
// deterministic object ordering.
Expand Down Expand Up @@ -108,17 +115,16 @@ const TimeAgo = memo<TimeAgoProps>(
return () => clearInterval(intervalId);
}, [unit, doUpdate]);

return timeElement ? (
<time
title={dateObject.toLocaleString(locale)}
dateTime={dateObject.toISOString()}
>
{text}
</time>
) : (
// avoid using a JSX fragment to keep things simple
text
);
return timeElement
? createElement(
"time",
{
title: dateObject.toLocaleString(locale),
dateTime: dateObject.toISOString(),
},
text
)
: text;
}
);
TimeAgo.displayName = "TimeAgo";
Expand Down

0 comments on commit 35212f0

Please sign in to comment.