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

tiny-jsx

v1.1.10

Published

TinyJSX is a lightweight UI JavaScript library for developing user interfaces using functional components.

Downloads

110

Readme

TinyJSX

TinyJSX is a lightweight UI JavaScript library for developing user interfaces using functional components.

David David David David

GZip packages sizes

tiny-jsx.min.js.gz tiny-jsx-hooks.min.js.gz tiny-jsx-dom.min.js.gz tiny-jsx-router.min.js.gz

Brotli packages sizes

tiny-jsx.min.js.br tiny-jsx-hooks.min.js.br tiny-jsx-dom.min.js.br tiny-jsx-router.min.js.br


Usage

TinyJSX exposes an API which mimics the recent React Hooks implementation but is really small.

TinyJSX supports only functional components.

import TinyJSX from 'tiny-jsx';
import { render } from 'tiny-jsx/dom';
import useEffect from 'tiny-jsx/hooks/useEffect';
import useState from 'tiny-jsx/hooks/useState';

function Clock () {
  const [tick, setTick] = useState(0);
  useEffect(() => {
    const interval = setInterval(() => {
      setTick(tick + 1);
    }, 1000);
    return () => clearInterval(interval);
  }, [tick]);

  return (
    <div>Seconds: {tick}</div>
  );
}

render(<Clock />, document.body);

For smaller bundle sizes all hooks are exported on their own. You can still import the hooks from the above example like this:

import { useState, useEffect } from 'tiny-jsx/hooks';

Examples

Some simple examples can be found in the examples directory. You can also see the library in action using the UMD builds here:

Getting Started

Install

When using NodeJS with yarn or npm

$ yarn add tiny-jsx
or
$ npm install --save tiny-jsx

or in the browser

<script defer type="text/javascript" src="https://unpkg.com/tiny-jsx@latest/tiny-jsx.min.js"></script>
<script defer type="text/javascript" src="https://unpkg.com/tiny-jsx@latest/tiny-jsx-hooks.min.js"></script>
<script defer type="text/javascript" src="https://unpkg.com/tiny-jsx@latest/tiny-jsx-dom.min.js"></script>
<script defer type="text/javascript" src="https://unpkg.com/tiny-jsx@latest/tiny-jsx-router.min.js"></script>

Import

The tiny-jsx library allows for using named and default exports.

Named Imports:

import { createElement } from 'tiny-jsx';

// Tell Babel to transform JSX into createElement() calls:
/** @jsx createElement */

Default Imports:

import TinyJSX from 'tiny-jsx';

// Tell Babel to transform JSX into TinyJSX.createElement() calls:
/** @jsx TinyJSX.createElement */

Instead of declaring the @jsx pragma you can use it globally by adding it to your Babel config file

For Babel 5 and prior:

{ "jsxPragma": "TinyJSX.createElement" }

For Babel 6: Install the transform-react-jsx plugin and add it to the configuration file:

{
  "plugins": [
     ["transform-react-jsx", { "pragma": "TinyJSX.createElement" }]
  ]
}

For Babel 7: Install the @babel/plugin-transform-react-jsx plugin and add it to the configuration file:

{
  "plugins": [
    ["@babel/plugin-transform-react-jsx", { "pragma": "TinyJSX.createElement", "pragmaFrag": "TinyJSX.Fragment" }]
  ]
}

For TypeScript add to tsconfig.json:

{
  "jsx": "react",
  "jsxFactory": "TinyJSX.createElement"
}

Rendering

The TinyJSX transpile function converts JSX components into Virtual DOM elements (as describe here). In order to render the Virtual DOM elements in a browser, TinyJSX provides a render() function that creates the corresponding DOM tree and renders it into an element from the existing DOM tree.

import TinyJSX from 'tiny-jsx';
import { render } from 'tiny-jsx/dom'; 

render(<div>Hello World!</div>, document.body);