- 优先使用带有 hooks 的函数式组件:
- 现代化开发:在 Chakra UI 项目中,优先使用 React 函数式组件和 Hooks 进行开发,而不是类组件。
- 代码简洁性:Hooks 使得组件逻辑更易于组织和测试,减少了冗余代码。
- 逻辑复用:自定义 Hooks 可以轻松地在不同组件之间共享状态逻辑。
- 性能优化:结合
React.memo、useCallback和useMemo可以更好地控制组件的渲染行为,优化性能。 - 示例:
import { Box, Button, useToast } from '@chakra-ui/react'; import React, { useState, useCallback } from 'react'; function MyFunctionalComponent() { const [count, setCount] = useState(0); const toast = useToast(); const handleClick = useCallback(() => { setCount(prevCount => prevCount + 1); toast({ title: 'Count updated.', description: `Count is now ${count + 1}`, status: 'success', duration: 1000, isClosable: true, }); }, [count, toast]); return ( <Box p={4}> <Text>Count: {count}</Text> <Button mt={2}> Increment </Button> </Box> ); } - 与 Chakra UI 的兼容性:Chakra UI 的 Hooks(如
useColorMode,useDisclosure)与函数式组件无缝集成,提供了强大的功能扩展。
Chakra UI React Chakra UI General Preferences
使用 Chakra UI 的 React 组件的一般偏好,包括使用带有 hooks 的函数式组件
Chakra UI React Chakra UI General Preferences by liaosw97 · 8bb2b7e
npx skillmds@latest add liaosw97/chakra-ui-react-chakra-ui-general-preferences File contents
---name: chakra-ui-react-chakra-ui-general-preferencesdescription: 使用 Chakra UI 的 React 组件的一般偏好,包括使用带有 hooks 的函数式组件---- **优先使用带有 hooks 的函数式组件**: - **现代化开发**:在 Chakra UI 项目中,优先使用 React 函数式组件和 Hooks 进行开发,而不是类组件。 - **代码简洁性**:Hooks 使得组件逻辑更易于组织和测试,减少了冗余代码。 - **逻辑复用**:自定义 Hooks 可以轻松地在不同组件之间共享状态逻辑。 - **性能优化**:结合 `React.memo`、`useCallback` 和 `useMemo` 可以更好地控制组件的渲染行为,优化性能。 - **示例**: ```jsx import { Box, Button, useToast } from '@chakra-ui/react'; import React, { useState, useCallback } from 'react'; function MyFunctionalComponent() { const [count, setCount] = useState(0); const toast = useToast(); const handleClick = useCallback(() => { setCount(prevCount => prevCount + 1); toast({ title: 'Count updated.', description: `Count is now ${count + 1}`, status: 'success', duration: 1000, isClosable: true, }); }, [count, toast]); return ( <Box p={4}> <Text>Count: {count}</Text> <Button onClick={handleClick} mt={2}> Increment </Button> </Box> ); } ``` - **与 Chakra UI 的兼容性**:Chakra UI 的 Hooks(如 `useColorMode`, `useDisclosure`)与函数式组件无缝集成,提供了强大的功能扩展。
liaosw97/awesome-rules-skills/tree/main/plugins/chakra-ui/skills/chakra-ui-react-chakra-ui---general-preferences commit 8bb2b7e750
Frequently asked questions
Run npx skillmds@latest add liaosw97/chakra-ui-react-chakra-ui-general-preferences in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
使用 Chakra UI 的 React 组件的一般偏好,包括使用带有 hooks 的函数式组件 It is listed under Web & Frontend on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Capability flags: docs only. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
liaosw97 (@liaosw97) published this skill. Their other Agent Skills are listed on their SkillMD profile.