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

v2.1.1

Published

React Abode is a simple React micro-frontend framework allowing you to host multiple react components by defining HTML.

Downloads

746

Readme

React Abode

React Abode is a simple React micro-frontend framework allowing you to host multiple react components by defining HTML.

Features

Prop passing

React Abode allows you to pass props to your React components by using a data-prop-prop-name attribute. All props need to be prefixed by data-prop-. Props will automatically be converted from kebab-case to camelCase.

<div data-component="Price" data-prop-sku="123456"></div>

Script props

React Abode allows you to pass data-prop- props to the script. These can then be consumed inside your bundle by using getScriptProps(). This is useful when you need to have a prop available in every component.

<script
  src="your/bundle/location.js"
  data-prop-global-prop="some prop you want in all your components"
></script>
const scriptProps = getScriptProps();
console.log(scriptProps.globalProp);

Prop parsing

By default all supplied props will be parsed with JSON.parse. In case a prop should be parsed differently, custom parse functions can be provided to register or getScriptProps.

// <div data-component="Product" data-prop-sku="1234" data-prop-is-available="true" data-prop-price="10.99" >
register('Product', () => import('./modules/Product/Product'), {
  propParsers: {
    sku: prop => String(prop),
    isAvailable: prop => Boolean(prop),
    price: prop => Float(prop),
  },
});
// <script data-prop-global="1234"></script>
getScriptProps({ propParsers: { global: prop => String(prop) } });
  • default JSON.parse
  • custom prop parsing function

Automatic DOM node detection

When DOM nodes are added, for example when loading more products in a catalog on a SPA, React Abode will automatically detect them and populate them with your React components. When a DOM node containing a hosted React component is removed, the component is unmounted.

Update on prop change

When the props for your components change, React Abode will rerender these components. This can be very useful when nesting multiple layers of front-end frameworks.

How to use

Create a bundle with one or more abode registered components. This takes the place of the App component in a create-react-app, which links the top level react component to the html page. When all components are registered, call populate. Build and host this bundle on your platform of choice.

// src/modules/Cart/Cart.tsx
const Cart = (): JSX.Element => {
  return <h1>a shopping cart</div>;
};

// src/App.tsx
import { populate, register } from 'react-abode';

// Import can be used to register component
register('Cart', () => import('./modules/Cart/Cart'));

// Component can also be used directly
import Cart from './modules/Cart/Cart';

register('Cart', () => React.memo(Cart));

populate({ attributes: { classname: 'some-class-name' } });

Include a div with the selector in your HTML. Load the bundle in a script tag inside the <body> </body>. On loading the page, React Abode will check for components with the matching selector, which is data-component by default.

<html>
  <body>
    <div data-component="Cart">
      This text wil be replaced by your react component
    </div>
    <script src="your/bundle/location.js"></script>
  </body>
</html>

Options

Utility functions

setComponentSelector

If you do not want to use data-component you can change the component selector by using setComponentSelector('data-my-component-selector').

getActiveComponents

You can use getActiveComponents to get a list of all Abode elements currently in your DOM.

getRegisteredComponents

You can use getRegisteredComponents to get all registered components.

Populate parameters

The populate function can be passed an object with options.

| name | type | purpose | example | | ---------- | -------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------- | | attributes | object | attributes which will be aplied to every react-abode container | {attributes: { classname: "some-class-name"}} | | callback | function | function which will be executed every time a new batch of react-abode elements is populated | () => console.log('new abode elements added to page') |

Contributing

After having commited your changes, run pnpm changeset and specify an appropriate bump type and a message. If you want to use your commit message(s) as the changeset message, run pnpm get:changes which copies all commit message(s) to your clipboard which you can then paste when running pnpm changeset.