@twocatmoon/react-slot

A cleaner alternative for managing children in React components via named slots.


Keywords
react, slot, control flow, control-flow
License
MIT
Install
npm install @twocatmoon/react-slot@0.2.0

Documentation

Contributors Forks Stargazers Issues MIT License


React Slot

A cleaner alternative for managing children in React components via named slots.
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Installation
  3. Usage
  4. Contributing
  5. License
  6. Contact
  7. Acknowledgments

About The Project

React Slot implements a content distribution API inspired by Vue.js and the Web Components spec draft, using the <Slot> element to serve as distribution outlet for content.

This allows you to compose components like this:

<SectionHeader>
  <Slot name='title'>Hello</Slot>
  <Slot name='subtitle'>Lorem ipsum dolor sit amet.</Slot>
</SectionHeader>

Then in the template for <Header>, you might have:

const slots = findSlots(props.children)

return (
  <header>
    <h1>{slots.title}</h1>
    <p>{slots.subtitle}</p>
  </header>
)

Slots can contain any template code, including HTML or even other components.

Any children not contained inside of a <Slot> will be assigned to slots.defaultSlot.

(back to top)

Built With

(back to top)

Installation

  1. Install from NPM
    npm i @twocatmoon/react-slot
  2. Include in your project
    import { Slot, findSlots } from '@twocatmoon/react-slot'

(back to top)

Usage

Please refer to the Documentation

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

Twitter - @twocatmoon

Project Link - https://github.com/twocatmoon/react-slot

(back to top)

Acknowledgments

(back to top)