Giter Site home page Giter Site logo

babel-plugin-jsx-factory's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.