# react-better-slot

> 用React实现的Vue中Slot的功能

Latest version **0.0.4** (published 2019-10-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-better-slot
pnpm add react-better-slot
yarn add react-better-slot
bun add react-better-slot
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2019-10-16 |
| First published | 2019-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jiangzhifeng |
| Maintainers | jiangzhifeng |
| Keywords | slot, react-slot |

## Links

- npm: https://www.npmjs.com/package/react-better-slot
- Repository: https://github.com/ghostjzf/react-better-slot
- Homepage: https://github.com/ghostjzf/react-better-slot#readme
- Issues: https://github.com/ghostjzf/react-better-slot/issues
- npm.io page: https://npm.io/package/react-better-slot

## Recent versions

- 0.0.4 (latest) — 2019-10-16
- 0.0.3 — 2019-10-16
- 0.0.2 — 2019-10-12
- 0.0.1 — 2019-10-12

## README

# react-better-slot

组件参照 Vue 中插槽的功能，基于 React 实现。

[更新日志](https://github.com/ghostjzf/react-better-slot/blob/master/CHANGELOG.md)

### 使用

```
npm install react-better-slot
```

### 示例代码

```
import React from "react";
import {withSlot, Slot} from "react-better-slot";


function AppLayout() {
    return (
        <div class="container">
            <header>
                <Slot name="header">如果没有传具名Slot的内容显示此内容</Slot>
            </header>
            <main>
                <Slot></Slot>
            </main>
            <footer>
                <Slot name="footer"></Slot>
            </footer>
        </div>
    )
}

export default withSlot(AppLayout);
```

```
import AppLayout from "./AppLayout";

<AppLayout>
    <template slot="header">
        <h3>这是标题</h3>
    </template>
    <template>
        <div>这是默认Slot显示的部分</div>
    </template>
    <template slot="footer">
        <p>这是页尾</p>
    </template>
</AppLayout>
```

```
最终效果

<div class="container">
    <header>
        <h3>这是标题</h3>
    </header>
    <main>
        <div>这是默认Slot显示的部分</div>
    </main>
    <footer>
        <p>这是页尾</p>
    </footer>
</div>
```

### 说明

-   该组件只会搜集第一个匹配到的没有指定 slot="xxxx"默认 template 模板, 如果存在多个除第一个将会被忽略并且给出 warning 提示
-   必须使用 template 标签作为模板容器

---
_Source: https://npm.io/package/react-better-slot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
