Socket
Book a DemoInstallSign in
Socket

babel-plugin-jsx-factory

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-jsx-factory

babel plugin for jsx handled by a function h(tagName, attributes, children)

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
3
200%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-jsx-factory

Use jsx with a factory function h matching this signature:

h(tagName, attributes, children)

For a string tagName, attributes object, and an array of children.

browserify virtual-dom example

Write some code with inline jsx and a virtual dom factory function, in our case h:

var h = require('virtual-dom/h');
var main = require('main-loop');
var loop = main({ n: 0 }, render, require('virtual-dom'));

function render (state) {
  return <div>
    <h1>clicked {String(state.n)} times</h1>
    <button onclick={onclick}>click me!</button>
  </div>

  function onclick () {
    loop.update({ n: state.n + 1 })
  }
}

Then make a package.json:

{
  "name": "whatever",
  "browserify": {
    "transform": [
      [
        "babelify",
        {
          "jsxPragma": "h",
          "plugins": [ "babel-plugin-jsx-factory" ]
        }
      ]
    ]
  },
  "dependencies": {
    "babelify": "^6.1.3",
    "babel-plugin-jsx-factory": "^1.0.0",
    "main-loop": "^3.1.0",
    "virtual-dom": "^2.0.1"
  }
}

To build:

$ browserify main.js > public/bundle.js

browserify react example

var React = require('react')
var App = React.createClass({
  getInitialState: function () { return { n: 0 } },
  render: function () {
    return <div>
      <h1>clicked {this.state.n} times</h1>
      <button onClick={this.handleClick}>click me!</button>
    </div>
  },
  handleClick: function () {
    this.setState({ n: this.state.n + 1 })
  }
})
React.render(<App />, document.querySelector('#content'))

Then make a package.json:

{
  "name": "whatever",
  "browserify": {
    "transform": [
      [
        "babelify",
        {
          "jsxPragma": "React.createElement",
          "plugins": [ "babel-plugin-jsx-factory" ]
        }
      ]
    ]
  },
  "dependencies": {
    "babelify": "^6.1.3",
    "babel-plugin-jsx-factory": "^1.0.0",
    "react": "~0.13.3"
  }
}

To build:

$ browserify main.js > public/bundle.js

license

MIT

Keywords

babel

FAQs

Package last updated on 01 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts