Entities
When to use?
When a lot of deunified logic appears in the project, often tied to specific entities
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} />
))}
...
)
}
Was this page helpful?
Your feedback helps us improve the docs