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 :)
There is demo project sourcecode.
Live demo and playground are not ready yet.
Library is not production-ready. Our development plan is described in GitHub Project and GitHub Issues
Use your favorite package manager:
pnpm i react-declarative-render
yarn i react-declarative-render
npm i react-declarative-render
You can refer to the demo project to play with the library.
- Declare a list of slots as an enum.
export enum SlotsEnum {
LOGO = 'LOGO',
CLICKER = 'CLICKER',
DOCS = 'DOCS'
}
- Declare props types accepted by slots.
export type SlotsPropsTypes = {
[SlotsEnum.CLICKER]: Record<string, unknown>
[SlotsEnum.LOGO]: Record<string, unknown>
[SlotsEnum.DOCS]: Record<string, unknown>
}
- Init
UISystemService
import { UISystemService } from 'react-declarative-render'
import { type SlotsPropsTypes } from './components/SlotsPropsTypes'
const uiSystemService = new UISystemService<SlotsPropsTypes>({ rootElementName: 'react-declarative-render-root' })
At the places of desired render, place UISlot
components with specified IDs.
<UISystemSlot id={SlotsEnum.LOGO} uiSystemService={uiSystem} />
uiSystem.registerComponent({
id: SlotsEnum.LOGO,
component: <Logo />
})
Pull requests are pretty much welcome.