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

react-ray

v1.1.2

Published

React integration for the Ray app

Downloads

77

Readme

react-ray

React integration for the Ray app.

Installation

You can install the package via npm:

npm install react-ray

Usage

react-ray supports React 16+ and provides two hooks:

  • useRay - send data to the Ray app whenever it updates.
  • useRayWithElement - send the contents of an element ref to the Ray app, optionally updating the item in place when its dependencies change.

useRay()

To send data to Ray whenever it updates, use the useRay hook along with the type option to specify the type of data you are sending. The boolean replace option can be used to update the Ray item in place when its dependencies change. The default value for replace is false.

Valid types are image, json, html, text, or xml. See the node-ray documentation for more information on these types.

import { useRay } from 'react-ray';
import { useEffect, useState } from 'react';

const MyComponent = () => {
    const [count, setCount] = useState(0);

    useRay(count, { type: 'text', replace: true });

    return (
        <button onClick={() => setCount(count + 1)}>
            Click me
        </button>
    );
};

useRayWithElement()

To send the contents of a ref to the Ray app in a sequential manner (each dependency change sends a new item), set the replace option to false:

import { useRayWithElement } from 'react-ray';
import { useRef, useState } from 'react';

const MyComponent = () => {
    const [count, setCount] = useState(0);
    const countRef = useRef(null);

    useRayWithElement(countRef, [count], { replace: false });

    return (
        <div>
            <div ref={countRef}>{count}</div>
            <button onClick={() => setCount(count + 1)}>
                Click me
            </button>
        </div>
    );
};

react-ray-02

To update the Ray item in place that was sent with the contents of a ref when its dependencies change, set the replace option to true or omit it:

import { useRayWithElement } from 'react-ray';
import { useRef, useState } from 'react';

const MyComponent = () => {
    const [count, setCount] = useState(0);
    const countRef = useRef(null);

    useRayWithElement(countRef, [count], { replace: true });
    // or
    // useRayWithElement(countRef, [count]);

    return (
        <div>
            <div ref={countRef}>{count}</div>
            <button onClick={() => setCount(count + 1)}>
                Click me
            </button>
        </div>
    );
};

react-ray-01

useRayInstance()

To access the Ray instance directly, use the useRayInstance hook:

import { useRayInstance } from 'react-ray';

const MyComponent = () => {
    const ray = useRayInstance();

    ray('hello world');

    return (
        <div>
            <button onClick={() => ray('hello world')}>
                Click me
            </button>
        </div>
    );
};

Setup

npm install

npm run dev

Testing

react-ray uses Jest for unit tests. To run the test suite:

npm run test


Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.