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 🙏

© 2026 – Pkg Stats / Ryan Hefner

jsx-to-call

v1.1.3

Published

### converting JSX syntax to a function call.

Readme

jsx-to-call

converting JSX syntax to a function call.

Sometimes we want to have isolated parts of our code to be used as a React Component but in a non React environment.

How?

jsx-to-call is a library that converts JSX syntax to a function call. It's like React.createElement but for different environment.

Installation

npm install jsx-to-call

Configuration

Add the following to your tsconfig.json file.

{
  "compilerOptions": {
    "jsx": "react",
    "jsxFactory": "JSX.createCall",
    "jsxFragmentFactory": "JSX.Fragment"
  }
}

Usage

import JSX from "jsx-to-call";

function ComponentA() {
  console.log("ComponentA");
}

function App() {
  return <ComponentA />;
}

why?

When we have a non React environment and we want to have reusable parts of our code. We can use jsx-to-call to create components and reuse them in different places.

Why not a simple function?

A simple function can be used but it's not as readable as JSX syntax. JSX syntax is more readable and easier to understand.

Why not React?

React is a great library for building UIs but not for non UI parts of the code. jsx-to-call is for non UI parts of the code.

Example

ex: This is a K6 test script to test a website. a non React environment.

import http from "k6/http";
import {check} from "k6";

export default function (){
    const homePageRes = http.get("https://exmaple.com/");
    check(homePageRes, {
        "status is 200": (r) => r.status === 200 && r.body.includes("Welcome to Example")
    });

    if(homePageRes.status !== 200){
        return;
    }

    const headerRes = http.get("https://exmaple.com/api/v1/header");

    function validateHeaderMenu(menu){
        return menu.includes("Home") && menu.includes("About") && menu.includes("Contact");

    check(headerRes, {
        "status is 200": (r) => r.status === 200 && validateHeaderMenu(r.json().menu)
    });

    const heroBannerRes = http.get("https://exmaple.com/api/v1/hero-banner");

    function validateHeroBanner(banners){
        // should have a title, description, and a image.
        return banners.length > 0 && banners[0].title && banners[0].description && banners[0].image;
    }

    check(heroBannerRes, {
        "status is 200": (r) => r.status === 200 && validateHeroBanner(r.json().banners)
    });

    const articlesRes = http.get("https://exmaple.com/api/v1/articles");

    function validateArticles(articles){
        return articles.length === 5 && articles.every(article => article.title && article.description && article.image);
    }

    check(articlesRes, {
        "status is 200": (r) => r.status === 200 && validateArticles(r.json().articles)
    });

    const footerRes = http.get("https://exmaple.com/api/v1/footer");

    function validateFooterMenu(menu){
        return menu.includes("English") && menu.includes("Spanish") && menu.includes("French") && menu.includes("Facebook") && menu.includes("Twitter") && menu.includes("Instagram");
    }

    check(footerRes, {
        "status is 200": (r) => r.status === 200 && validateFooterMenu(r.json().menu)
    });
}

So imagine we have the above code in something like a React environment. We can create components for each part of the page and reuse them in different places.

import JSX from "jsx-to-call";
import HomePage from "./page/HomePage";
import Header from "./components/Header";
import HeroBanner from "./components/HeroBanner";
import Articles from "./components/Articles";
import Footer from "./components/Footer";

export default function () {
  return (
    <HomePage>
      <Header />
      <HeroBanner />
      <Articles />
      <Footer />
    </HomePage>
  );
}

And let check the Header component.

import http from "k6/http";
import {check} from "k6";

export default function Header() {
    const headerRes = http.get("https://exmaple.com/api/v1/header");

    function validateHeaderMenu(menu){
        return menu.includes("Home") && menu.includes("About") && menu.includes("Contact");

    check(headerRes, {
        "status is 200": (r) => r.status === 200 && validateHeaderMenu(r.json().menu)
    });
}

So we have a Header component that we can reuse in different places. like a React component.

Props

We can pass props to the components like in React.

ex:

import http from "k6/http";
import { check } from "k6";

function Articles({ maxArticles }: { maxArticles: number }) {
  const articlesRes = http.get(
    "https://exmaple.com/api/v1/articles?maxArticles=" + maxArticles
  );

  function validateArticles(articles) {
    return (
      articles.length === maxArticles &&
      articles.every(
        (article) => article.title && article.description && article.image
      )
    );
  }

  check(articlesRes, {
    "status is 200": (r) =>
      r.status === 200 && validateArticles(r.json().articles),
  });
}

and then use it like this

<Articles maxArticles={5} />

Like a React component.

Babel Settings

If you are using Babel, you can use the following settings:

{
  "presets": [
    [
      "@babel/preset-react",
      {
        "pragma": "JSX.createCall",
        "pragmaFrag": "JSX.Fragment"
      }
    ]
  ]
}