npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

temporal-react-hook

v1.2.0

Published

<div> <h1>temporal-react-hook</h1> <h6>react-temporal-hooks is a React library that provides hooks for handling date and time operations using the Temporal API.</h6> </div>

Downloads

4

Readme

Available hooks:

useTemporal

useTimeZone

useDuration

Description for Hooks

useTemporal hook

Features:

  • Real-time Updates: The hook updates the current date and time every second.
  • Temporal API Integration: Utilizes the Temporal API for precise and reliable date and time handling.
  • Ease of Use: Simple to integrate and use in any React component.

Example Usage:

npm install temporal-react-hook
import React from 'react';
import { useTemporal } from 'your-package-name';

const App: React.FC = () => {
  const now = useTemporal();

  return (
    <div>
      <h1>Current Date and Time</h1>
      <p>{now.toString()}</p>
    </div>
  );
};

export default App;

Benefits

  • Accuracy: Temporal API provides nanosecond precision and handles time zones and calendar systems better than the traditional Date object.
  • Simplicity: The hook abstracts the complexity of handling real-time updates, making it easy to display current date and time in your React application.
  • Immutable: Temporal objects are immutable, ensuring that each update generates a new instance without modifying the original object.

Potential Use Cases

  • Clock Display: Displaying a real-time clock in your application.
  • Time-based Events: Triggering actions or displaying messages based on the current time.
  • Logging and Monitoring: Showing timestamps for logs or monitoring data in real-time applications.

useTimeZone hook

Features:

  • Current Time Zone: Provides the current time zone.
  • Time Zone Conversion: Converts a given PlainDateTime to a specified time zone.

Example Usage

npm install temporal-react-hook
import React from 'react';
import { useTemporal, useTimeZone } from 'your-package-name';

const App: React.FC = () => {
    const now = useTemporal();
    const { timeZone, convertToTimeZone } = useTimeZone();

    const newYorkDateTime = convertToTimeZone(now, 'America/New_York');

    return (
        <div>
            <h1>Current Date and Time</h1>
            <p>{now.toString()}</p>
            <h2>Time Zone</h2>
            <p>{timeZone.toString()}</p>
            <h2>New York Time</h2>
            <p>{newYorkDateTime.toString()}</p>
        </div>
    );
};

export default App;

Benefits

  • Current Time Zone Information The hook provides easy access to the current time zone of the user's environment, allowing your application to adapt to the user's locale without additional configuration.
  • Time Zone Conversion: The hook includes a built-in function to convert any given date-time to a specified target time zone, which simplifies handling global time zones in applications. This is particularly useful for applications that display events or schedules across different time zones.
  • Simplifies Complex Logic: By abstracting the complexity of time zone handling, this hook makes it easier for developers to implement and maintain code that involves date-time manipulations across different time zones.

useDuration hook

Features:

  • Create Durations: Easily create durations from various units (e.g., hours, minutes, days).
  • Add or Subtract Durations: Perform addition or subtraction of durations to/from date-times.
  • Format Durations: Format durations in a human-readable string..

Example Usage

npm install temporal-react-hook
import React from 'react';
import { useTemporal, useTimeZone, useDuration } from 'react-temporal-hooks';

const App: React.FC = () => {
    const now = useTemporal();
    const { timeZone, convertToTimeZone } = useTimeZone();
    const { createDuration, addDuration, subtractDuration, formatDuration } = useDuration();

    const newYorkDateTime = convertToTimeZone(now, 'America/New_York');

    const duration = createDuration({ hours: 2, minutes: 30 });
    const addedDateTime = addDuration(now, duration);
    const subtractedDateTime = subtractDuration(now, duration);

    return (
        <div>
            <h1>Current Date and Time</h1>
            <p>{now.toString()}</p>
            <h2>Time Zone</h2>
            <p>{timeZone.toString()}</p>
            <h2>New York Time</h2>
            <p>{newYorkDateTime.toString()}</p>
            <h2>Duration</h2>
            <p>{formatDuration(duration)}</p>
            <h2>Added Duration</h2>
            <p>{addedDateTime.toString()}</p>
            <h2>Subtracted Duration</h2>
            <p>{subtractedDateTime.toString()}</p>
        </div>
    );
};

export default App;

Benefits

  • Simplified Duration Management: Easily create and manage durations using the Temporal API.
  • Duration Operations: Perform addition and subtraction operations with durations, enhancing date-time manipulation capabilities.
  • Improved User Experience: Provides precise duration handling, which is essential for applications that involve scheduling, timers, and time calculations.