Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/developit/preact-views

📺 Named views for Preact, with easy-as-pie linking between them.
https://github.com/developit/preact-views

preact preact-components preact-router routing

Last synced: 28 days ago
JSON representation

📺 Named views for Preact, with easy-as-pie linking between them.

Awesome Lists containing this project

README

        

# preact-views

[![NPM](http://img.shields.io/npm/v/preact-views.svg)](https://www.npmjs.com/package/preact-views)
[![travis-ci](https://travis-ci.org/developit/preact-views.svg)](https://travis-ci.org/developit/preact-views)

**Named views for [Preact], with easy-as-pie linking between them!**

`preact-views` provides a `` component that renders its children only when their `name` prop is selected as the current "view". The current view name can be set via a prop, or automatically through the provided `` component.

> **Note:** `preact-views` is simple and does not do orchestration or routing for you. If you're looking for a URL router, try [preact-router](https://github.com/developit/preact-router).

#### [See a Real-world Example :arrow_right:](https://jsfiddle.net/developit/jz95kc33/)

---

### Complete Example

```js
import { Views, Link } from 'preact-views';
import { h, render } from 'preact';

const Home = () => (


Home!


Go Other

);

const Other = ({ value=0 }) => (


Other.


Go Home

value is {value}.


Increment

);

render((




), document.body);
```

[**See it running :arrow_right:**](https://jsfiddle.net/developit/jz95kc33/)

---

### Simple Example

```js
import Views from 'preact-views';
import { h, render } from 'preact';

render((

one

two


), document.body);

// renders a div containing the text "one"
```

---

### License

[MIT]

[Preact]: https://github.com/developit/preact
[MIT]: http://choosealicense.com/licenses/mit/