Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)48k · #6244

zustand-store-ts

Skill này làm gì

Đoạn mã này giúp tạo một “store” dữ liệu cho ứng dụng web bằng thư viện Zustand. Nó sắp xếp cách dữ liệu được lưu giữ, cách bạn truy cập và thay đổi dữ liệu, đảm bảo mọi thứ hoạt động đúng với TypeScript.

Khi nào nên dùng

  • ✓Khi bạn cần lưu thông tin mà nhiều phần của ứng dụng sẽ dùng.
  • ✓Khi xây dựng hệ thống quản lý trạng thái cho dự án của bạn.
  • ✓Khi sắp xếp dữ liệu toàn cục thay đổi theo thời gian.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/zustand-store-ts/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/zustand-store-ts/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tạo một store để quản lý trạng thái giỏ hàng, bao gồm các sản phẩm và tổng tiền, với các hàm để thêm và xóa sản phẩm.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ dùng một mẫu để định nghĩa những gì cần lưu (state) và những việc cần làm với dữ liệu đó (actions). Nó cũng đảm bảo chỉ những phần cần thiết của ứng dụng được cập nhật khi dữ liệu thay đổi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Zustand Store

Create Zustand stores following established patterns with proper TypeScript types and middleware.

Quick Start

Copy the template from assets/template.ts and replace placeholders:

  • {{StoreName}} → PascalCase store name (e.g., Project)
  • {{description}} → Brief description for JSDoc

Always Use subscribeWithSelector

import { create } from 'zustand';
import { subscribeWithSelector } from 'zustand/middleware';

export const useMyStore = create<MyStore>()(
  subscribeWithSelector((set, get) => ({
    // state and actions
  }))
);

Separate State and Actions

export interface MyState {
  items: Item[];
  isLoading: boolean;
}

export interface MyActions {
  addItem: (item: Item) => void;
  loadItems: () => Promise<void>;
}

export type MyStore = MyState & MyActions;

Use Individual Selectors

// Good - only re-renders when `items` changes
const items = useMyStore((state) => state.items);

// Avoid - re-renders on any state change
const { items, isLoading } = useMyStore();

Subscribe Outside React

useMyStore.subscribe(
  (state) => state.selectedId,
  (selectedId) => console.log('Selected:', selectedId)
);

Integration Steps

  1. Create store in src/frontend/src/store/
  2. Export from src/frontend/src/store/index.ts
  3. Add tests in src/frontend/src/store/*.test.ts

When to Use

This skill is applicable to execute the workflow or actions described in the overview.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Câu hỏi thường gặp

“Zustand” là gì?

Zustand là thư viện giúp việc quản lý dữ liệu trong ứng dụng web dễ dàng hơn.

“TypeScript” là gì?

TypeScript là ngôn ngữ lập trình thêm các kiểm tra bổ sung để giúp ngăn ngừa lỗi trong mã của bạn.

“Middleware” là gì?

Middleware giống như các “plugin” thêm tính năng cho store, như ghi nhật ký các thay đổi hoặc xử lý các hành động bất đồng bộ.

Chi tiết

Mô tả gốc của tác giả

Create Zustand stores following established patterns with proper TypeScript types and middleware.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#6244
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự