Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/savolkov/react-declarative-render

A lightweight library for declarative render of React components. Declaratively render any component from any piece of code without having unnecessary dependencies and decrease spaghetti-styled code :)
https://github.com/savolkov/react-declarative-render

architecture declarative react

Last synced: 17 days ago
JSON representation

A lightweight library for declarative render of React components. Declaratively render any component from any piece of code without having unnecessary dependencies and decrease spaghetti-styled code :)

Awesome Lists containing this project

README

        

# react-declarative-render

> A lightweight library for declarative render of React components.
>
> Declaratively render any component from any piece of code without having unnecessary dependencies and decrease spaghetti-styled code :)

---

## Demo

There is [demo project sourcecode](https://github.com/savolkov/react-declarative-render/tree/main/demo/react-declarative-render-demo).

Live demo and playground are not ready yet.

## Current state

Library is not production-ready. Our development plan is described in [GitHub Project](https://github.com/users/savolkov/projects/1) and [GitHub Issues](https://github.com/savolkov/react-declarative-render/issues/)

## Installation

Use your favorite package manager:

### pnpm

```bash
pnpm i react-declarative-render
```

### yarn

```bash
yarn i react-declarative-render
```

### npm

```bash
npm i react-declarative-render
```

## Usage

You can refer to the [demo project](https://github.com/savolkov/react-declarative-render/tree/main/demo/react-declarative-render-demo) to play with the library.

### 1. Preparating infrastructure

1. Declare a list of slots as an enum.
```tsx
export enum SlotsEnum {
LOGO = 'LOGO',
CLICKER = 'CLICKER',
DOCS = 'DOCS'
}
```
2. Declare props types accepted by slots.
```tsx
export type SlotsPropsTypes = {
[SlotsEnum.CLICKER]: Record
[SlotsEnum.LOGO]: Record
[SlotsEnum.DOCS]: Record
}
```

3. Init `UISystemService`

```tsx
import { UISystemService } from 'react-declarative-render'
import { type SlotsPropsTypes } from './components/SlotsPropsTypes'

const uiSystemService = new UISystemService({ rootElementName: 'react-declarative-render-root' })
```

### 2. Place UISlots

At the places of desired render, place `UISlot` components with specified IDs.

```tsx

```

### 3. Render components

```tsx
uiSystem.registerComponent({
id: SlotsEnum.LOGO,
component:
})
```

## Contributing

Pull requests are pretty much welcome.

## License

[MIT](https://github.com/savolkov/react-declarative-render/blob/main/license)