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

v1.0.15

Published

A Typescript Wrapper for React.CreateElement(), that makes writing react components more like html. Essentially React+Typescript (NO JSX)

Downloads

12

Readme

React-TSX

React-TSX is a typescript library that makes writing compiled react code using Typescript simple and look very close to html, if it were functional programming.

Reason for react-tsx

The reason react-tsx was created is that Typescript does not always play well with jsx, and at the time I started learning React it was almost impossible to use both. I personally do not like the look, feel, syntax, and the extra build step that is required to use jsx.

Screw IDEs I only code in vim, nano, less, vi, etc..

You need to manually add the following to your files section of your tsconfig.json

"files":[
  "path-to-src/entry-file.tsx",
  "path-to-src/all-other-src-files.tsx",
  "node_modules/react-tsx/js/index.d.ts",
  "node_modules/react-tsx/js/src/react-tsx.d.ts",
  "node_modules/react-tsx/ts/typings/globals/react-tap-event-plugin/index.d.ts",
  "node_modules/react-tsx/ts/typings/globals/react/index.d.ts",
  "node_modules/react-tsx/ts/typings/index.d.ts",
  "node_modules/react-tsx/ts/typings/modules/react-dom/index.d.ts",
  "node_modules/react-tsx/ts/typings/modules/react-router/index.d.ts"
]

Using react-tsx in a project with IDE re-write

If you are taking advantage of your IDE all you need is a properly configured tsconfig.json

List of IDEs I know of

  • Atom
  • Visual Studio
  • Visual Studio Code
  • WebStorm

IDE re write

"your-ide": {
    "rewriteTsconfig": true
}

compilerOptions

The required compiler options you can use es5 or es6, it's your choice!

"compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "isolatedModules": false,
    "moduleResolution": "node",
    "jsx": "react"
}

filesGlob if you are using a supported IDE

The last line in the fileGlobs is what picks up react.d.ts, react-dom.d.ts, react-router.d.ts, and react-tap-event-plugin.d.ts. This is so you do not have to deal with the definition files and can use import React = require("react") etc. anywhere.

"filesGlob": [
        "<insert path to source dir/>/**/*.ts",
        "<insert path to source dir/>/**/*.tsx",
        "<insert path to node_modules/>/react-tsx/**/*.d.ts"
    ],

My starter tsconfig.json

Please note that I did not fill out files:[], my IDE did!

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "isolatedModules": false,
        "moduleResolution": "node",
        "jsx": "react",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "sourceMap": true,
        "noLib": false,
        "preserveConstEnums": true,
        "suppressImplicitAnyIndexErrors": true
    },
    "filesGlob": [
        "src/**/*.ts",
        "src/**/*.tsx",
        "node_modules/react-tsx/**/*.d.ts"
    ],
    "compileOnSave": true,
    "buildOnSave": false,
    "files": [
        "src/index.tsx",
        "node_modules/react-tsx/js/index.d.ts",
        "node_modules/react-tsx/js/src/react-tsx.d.ts",
        "node_modules/react-tsx/ts/typings/globals/react-tap-event-plugin/index.d.ts",
        "node_modules/react-tsx/ts/typings/globals/react/index.d.ts",
        "node_modules/react-tsx/ts/typings/index.d.ts",
        "node_modules/react-tsx/ts/typings/modules/react-dom/index.d.ts",
        "node_modules/react-tsx/ts/typings/modules/react-router/index.d.ts"
    ],
    "atom": {
        "rewriteTsconfig": true
    }
}

Bundlign Time: Browserify, Webpack, etc..

You will need to use a commonjs bundler, this is agnostic so pick your poison.

Full Example

For a full example please see my example using react-toolbox(http://react-toolbox.com/#/) and webpack (https://github.com/Thecavepeanut/react-tsx-basic-example)

Basic Example With No JSX

import {Props, Component, el, ul, li, div, table, thead, th, tbody, tr, td} from "react-tsx";

interface MyComponentProps extends Props {

}

interface MyComponentState {

}

class MyComponent extends Component<MyComponentProps, MyComponentState>{
  render() {
    return div({ className: "my-component-wrapper" },
      ul({},
        li({}, "1"),
        li({}, "2"),
        li({ onClick: () => { alert("you clicked 3") } }, "3")
      ),
      table({ className: "my-component-table" },
        thead({},
          tr({},
            th({}, "header 1"),
            th({}, "header 2"),
            th({}, "header 3")
          )
        ),
        tbody({},
          tr({},
            td({}, "cell 1-1"),
            td({}, "cell 1-2"),
            td({}, "cell 1-3")
          ),
          tr({},
            td({}, "cell 2-1"),
            td({}, "cell 2-2"),
            td({}, "cell 2-3")
          )
        )
      )
    )
  }
}

If Are Using JSX (*.tsx) import React

The compiled jsx will compile down to React.createElement thus you need to import React at the top of your files!

import React = require("react");

Example Source ex.tsx:

<div class="my-awesome-div"></div>

Now compiled ex.js:

React.createElement("div", {className:"my-awesome-div"})