# react-slots-hooks

> Use VueJS style slots in React

Latest version **1.0.0** (published 2022-05-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-slots-hooks
pnpm add react-slots-hooks
yarn add react-slots-hooks
bun add react-slots-hooks
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-05-03 |
| First published | 2022-05-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wilkinsonjack1993 |
| Maintainers | wilkinsonjack1993 |
| Keywords | slots, react, typescript |

## Links

- npm: https://www.npmjs.com/package/react-slots-hooks
- npm.io page: https://npm.io/package/react-slots-hooks

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-05-03

## README

# React Slots

Create slots within React Components in a similar way to Vue JS. This library supports Typescript

## Getting Stated

```
npm install react-slots
OR
yarn add react-slots
```

## Usage with Typescript

Create the component that will have slots inserted into it using the `useSlot` hook:

```
import { useSlots } from "react-slots";

interface LayoutSlots {
  header?: ReactNode;
  default?: ReactNode;
  footer?: ReactNode;
}

const Layout = (props: { children: ReactNode }) => {
  const { slots } = useSlots<LayoutSlots>(props.children);
  return (
    <div className="wrapper">
      <div className="header">{slots.header}</div>
      <div className="content">{slots.default}</div>
      <div className="footer">{slots.footer}</div>
    </div>
  );
};

```

Then when using this component, either use the template component or add the slot prop to indicate which slot the children belong to. Any sections without a slot attribute will be assigned to the default slot.

```
import { Template } from "react-slots-test";

<Layout>
    <div slot="header">Header</div>
    <p>test</p>
    <p>Content</p>
    <Template slot="footer">
        <p>Footer</p>
        <p>Footer2</p>
    </Template>
</Layout>
```

The Template component has only one prop 'slot'. This component can be used if you wish to put multiple parallel components within one specific slot.

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