Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

teact

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

teact

Generate React elements with CoffeeScript functions

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
48
increased by1100%
Maintainers
1
Weekly downloads
 
Created
Source

Teact

It's better than cjsx.

Build React element trees by composing functions.
You get full javascript control flow, and minimal boilerplate. It's also quite simple, just a thin wrapper around React.createElement like JSX.

Build Status NPM version

Usage

{crel} = require 'teact'

crel 'div', '#root.container', ->
  unless props.signedIn
    crel 'button', onClick: handleOnClick, 'Sign In'
  crel.text 'Welcome!'

Transforms into:

React.createElement('div',
  {id: root, className: 'container'}, [
    (props.signedIn ? React.createElement('button',
      {onClick: handleOnClick}, 'Sign In'
    ) : null)
    'Welcome!'
  ]
)

Use it from your component's render method:

{Component} = require 'react'
{crel} = require 'teact'

class Widget extends Component
  render: ->
    crel 'div', className: 'foo', ->
      crel 'div', 'bar'

Or in a stateless component:

module.exports = (props) ->
  crel 'div', className: 'foo', ->
    crel 'div', 'bar'

Nesting Components

crel is just a thin wrapper around React.createElement, so you can pass it components instead of crel names:

class DooDad extends Component
  render: ->
    crel 'div', className: 'doodad', =>
      crel 'span', @props.children

class Widget extends Component
  handleFiddle: =>
    # ...

  render: ->
    crel 'div', className: 'foo', =>
      crel DooDad, onFiddled: @handleFiddle, =>
        crel 'div', "I'm passed to DooDad.props.children"

Sugar Syntax

Teact exports bound functions for elements, giving you options for terser syntax if you're into that:

T = require 'teact'

T.div 'div', className: 'foo', ->
  T.text 'Blah!'

or the Teacup / CoffeeCup signatures:

{div, text} = require 'teact'

div 'div', '.foo', ->
  text 'Blah!'

Legacy

Markaby begat CoffeeKup begat CoffeeCup and DryKup which begat Teacup which begat React.

Contributing

$ git clone https://github.com/hurrymaplad/teact && cd teact
$ npm install
$ npm test

Keywords

FAQs

Package last updated on 04 Nov 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc