Skip to content

Commit ef9e8dc

Browse files
committed
fixed due to comment exept currentUnit clearly change
1 parent bb25fc0 commit ef9e8dc

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

dist/react-pure-time.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/react-pure-time.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const Time = (props: Props) => {
139139

140140
React.useEffect(() => {
141141
let interval: null | number = null;
142-
if (props.relativeTime && isDate(props.value) && !interval) {
142+
if (props.relativeTime && isDate(props.value)) {
143143
const date = new Date(props.value);
144144
const diff = getRelativeTimeDiff(date);
145145
state.currentUnit = props.unit || bestFit(diff);
@@ -148,10 +148,10 @@ const Time = (props: Props) => {
148148
...state,
149149
relativeTime: updateRelativeTime(date, state.currentUnit),
150150
});
151-
interval = window.setInterval(
152-
() => updateRelativeTime(date, state.currentUnit),
153-
getInterval(state.currentUnit)
154-
);
151+
interval = window.setInterval(() => {
152+
state.currentUnit = props.unit || bestFit(diff);
153+
updateRelativeTime(date, state.currentUnit);
154+
}, getInterval(state.currentUnit));
155155
}
156156

157157
return () => {

0 commit comments

Comments
 (0)