Socket
Socket
Sign inDemoInstall

phy-nb

Package Overview
Dependencies
1
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    phy-nb

Phy is a set of minimalist hyperscript helpers for Preact


Version published
Maintainers
1
Created

Changelog

Source

v4.2.7 (2022-07-26)

<a id="v4.2.7"></a>

🏡 Internal
  • #18 ci(actions): add GitHub actions (@aaarichter)
  • #25 accept falsey kids (@dbushong)

Readme

Source

nlm-github nlm-node nlm-version

phy

Minimal hyperscript helpers for Preact.

The intent while creating this package was to create as small of a footprint as possible, with only Preact as a dependency.

Examples

const h = require('phy');

module.exports = function SomeComponent() {
  return h('#foo', h('span.bar', 'whee!'));
}

or, if you need access to other things from Preact, Component and render are passed thru for your convenience:

const { h, Component } = require('phy');

class SomeComponent extends Component {
  render() {
    return h('#foo', h('span.bar', 'whee!'));
  }
}
module.exports = SomeComponent;

You can create a Fragment tersely by passing only one argument: an array of other nodes or strings:

const frag = h([
  h('div', 'one'),
  h('div', 'two'),
  'three'
]);

// is equivalent to:

const { Fragment } = require('preact');
const frag = h(Fragment, [
  h('div', 'one'),
  h('div', 'two'),
  'three'
]);

Optional Tag Helpers

At the cost of a modestly larger import and slight function call overhead, you can also use a set of named tag function helpers for terser syntax.

Important: bare string children must be enclosed in an array. h('div', 'kittens') or div(['kittens']) are ok, div('kittens') is NOT.

// h() is passed through as an export so you don't need to require preact
const { h, span, div } = require('phy/tags');

module.exports = function SomeComponent() {
  return div('#foo', [span(['kittens']), h(SomeOtherComponent)]);
}

License

BSD 3-Clause open source license

FAQs

Last updated on 01 Aug 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc