4.2.7 • Published 2 years ago

phy v4.2.7

Weekly downloads
18
License
BSD-3-Clause
Repository
github
Last release
2 years ago

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

4.2.7

2 years ago

4.2.6

3 years ago

4.2.5

3 years ago

4.2.4

3 years ago

4.2.3

4 years ago

4.2.2

4 years ago

4.2.1

4 years ago

4.2.0

4 years ago

4.1.0

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

6 years ago

3.0.1

6 years ago

2.0.0

7 years ago

1.0.0

8 years ago