Skip to main content

Entities

When to use?

When a lot of deunified logic appears in the project, often tied to specific entities

entities-themed-bordered

Description

There are usually placed:

  • business entities, for building the business logic of the application

    For example: user, order, post, journal, navigation, ...

  • components with the representation of entities, for building the UI of the overlying layers

    For example: UserCard, TweetCard, ...

Structure

โ””โ”€โ”€ entities/{slice}
โ”œโ”€โ”€ lib/
โ”œโ”€โ”€ model/
โ”œโ”€โ”€ ui/
โ””โ”€โ”€ index.ts

Examples

Using the Entity Model

**/**/index.tsx
import { viewerModel } from "entities/viewer";

export const Wallet = () => {
const viewer = viewerModel.useViewer();
const { moneyCount } = viewer;

...
}

Using Entity components

entities/book/index.ts
export { BookCard, ... } from "./ui";
export * as bookModel from "./model";
pages/**/index.tsx
import { BookCard } from "entities/book";

export const CatalogPage = () => {
const bookQuery = ...;
return (
...
{bookQuery.map((book) => (
<BookCard key={book.id} data={book} />
))}
...
)
}