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-gluons

v1.1.0

Published

React Gluons is a collection of utility components for building larger React components in a more declarative way, taking inspiration from SolidJS. These components aim to simplify common tasks and enhance the declarative nature of your React applications

Downloads

14

Readme

React Gluons

React Gluons is a collection of utility components for building larger React components in a more declarative way, taking inspiration from SolidJS. These components aim to simplify common tasks and enhance the declarative nature of your React applications.

Installation

npm install react-gluons

Usage

  • The Show component conditionally renders its children based on a boolean condition.
import React from 'react';
import {Show} from 'react-gluons';

function App() {
    const shouldShow = true;

    return (
        <Show when={shouldShow}>
            <p>This content is conditionally rendered</p>
        </Show>
    );
}

export default App;
  • The Hide component conditionally hides its children based on a boolean condition.
import React from 'react';
import {Hide} from 'react-gluons';

function App() {
    const hide = true;

    return (
        <Hide when={hide}>
            <p>This content is conditionally hidden</p>
        </Hide>
    );
}

export default App;
  • The Wrap component conditionally wraps its children with a specified wrapper component based on a condition.
import React from 'react';
import {Wrap} from 'react-gluons';

function Wrapper({ children }: { children: React.ReactNode }) {
    return <div className="wrapper">{children}</div>;
}

function App() {
    const shouldWrap = true;

    return (
        <Wrap when={shouldWrap} with={(children) => <Wrapper>{children}</Wrapper>}>
            <p>This is the content</p>
        </Wrap>
    );
}

export default App;

The Swap component is used to swap between different views or components based on a condition or state.

import React, { useState } from 'react';
import {Swap} from 'react-gluons';

function FirstComponent() {
  return <div>First Component</div>;
}

function SecondComponent() {
  return <div>Second Component</div>;
}

function ThirdComponent() {
    return <div>Third Component</div>;
}

function App() {
  const [order, setOrder] = useState('first');

  return (
    <div>
        <Swap on={letter} >
            <Case is={'first'}>
                <FirstComponent/>
            </Case>
            <Case is={'second'}>
                <SecondComponent/>
            </Case>
            <Case is={'third'}>
                <ThirdComponent/>
            </Case>
        </Swap>
    </div>
  );
}

export default App;

The View component is used to render data in a formatted JSON view. It can handle various data types, including objects, arrays, strings, numbers, and booleans.

import React from 'react';
import View from 'react-gluons';

const data = {
  name: "John Doe",
  age: 30,
  hobbies: ["reading", "gaming", "coding"]
};

function App() {
  return <View data={data} />;
}

export default App;

The List component is used to render a list of items, with a custom render function for each item.

import React from 'react';
import List from 'react-gluons';

const items = ["Item 1", "Item 2", "Item 3"];

function App() {
    return (
        <List from={items} fallback={<div>empty!</div>}>
            {({label, ...rest}, index) => <Button label={label}/>}
        </List>
    );
}

export default App;

The Async component can handle asynchronous operations, such as data fetching, and display appropriate UI states for loading and errors.

import React, { lazy } from 'react';
import Async from './Async';

const LazyComponent = lazy(() => import('./LazyComponent'));

function App() {
    return (
        <Async
            fallback={<div>Loading...</div>}
            errorFallback={<div>Something went wrong! <button onClick={() => window.location.reload()}>Retry</button></div>}
            retry={true}
        >
            <LazyComponent />
        </Async>
    );
}

export default App;