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

v1.1.0

Published

Another one markup library for React.js inspired by hyperscript

Downloads

10

Readme

react-markup

Build Status

Another one markup library for React.js inspired by hyperscript. It allows use valid JavaScript code instead of JSX, like this:

import {h} from 'react-markup'

h("div",
    h("div#header.highlighted.hover",
        h("div.title", "People List")
    ),
    h("div.body", people.map( person => (
        h("div.person", {key:person.id}, person.name)
    ))),
    h("div#footer.hidden", "(footer content)")
)

// which analogue in JSX is:
<div>
    <div id="header" className="highlighted hover">
        <div>People list</div>
    </div>
    <div className="body">
        {
            people.map( person => (
                <div className="person" key={person.id}>{person.name}</div>
            )))
        }
    </div>
    <div id="footer" className="hidden">(footer content)</div>
</div> 

Installation

npm install --save react-markup

Motivation

Facebook developers encourage everybody use JSX in React code. However, this approach has several disadvantages:

  • a lot of IDE's and text editors, which support JS syntax, work bad with JSX syntax

  • it could be harder to properly set up your build process to transpile from JSX and from ES6 at the same time

  • some people think, that mix of JS and JSX is harder to read

Advantages

This library was inspired by different hyperscript-like libraries, including react-hyperscript and
virtual-hyperscript, but it has several advantages:

  • it is possible to pass child elements as array and as varargs, and semantic of these methods corresponds to React.createElements semantics (e. g. it requires to pass key property for children, passed as array);

  • it doesn't mutate properties (which is not true for react-hyperscript);

  • it faster than analogues.

More examples

Simple element:

// JSX
<div>Text content</div>

// react-markup
h('div', 'Text content')
// ...or
div('Text content')

Div with class and id

// JSX
<div className='highlighted' id='header'>
    Text content
</div> 

// react-markup
h('div#header.highlighted', 
    'Text content'
)

Passing children as varargs

// JSX
<div className='container'>
    <div>Header</div>
    <div>Body</div>
</div> 

// react-markup
h('div.container', 
    h('div', 'Header'),
    h('div', 'Body'),
)

Passing children as array

// JSX
<div className='container'>
    {
        items.map(x => (
            <div key={x.id}>{x.title}<div>
        ))
    }
</div> 

// react-markup
h('div.container', items.map(x => (
    h('div', {key:x.id}, x.title)
)))