Loading...
Loading...
Compare original and translation side by side
download.txtdownload.txtundefinedundefinedundefinedundefined{节点内容}.md{Node Content}.mdscripts/validate_document.pyscripts/validate_document.pyscripts/word_count.pyscripts/word_count.pyreferences/writing-guidelines.mdreferences/writing-guidelines.mdreferences/mermaid-cheatsheet.mdreferences/mermaid-cheatsheet.mdReact Hooks入门1_hooks_intro.md1_hooks_guide.md1_hooks_best_practices.mdReact Hooks入门.mdundefinedIntroduction to React Hooks1_hooks_intro.md1_hooks_guide.md1_hooks_best_practices.mdIntroduction to React Hooks.mdundefinedimport { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}| 模式 | 说明 | 示例 |
|---|---|---|
| 直接替换 | 简单类型 | |
| 函数式更新 | 依赖旧值 | |
| 对象更新 | 保留其他字段 | |
| Pattern | Description | Example |
|---|---|---|
| Direct Replacement | Simple types | |
| Functional Update | Depends on old value | |
| Object Update | Retain other fields | |
useEffect(() => {
// Side effect logic
document.title = `You clicked ${count} times`;
return () => {
// Cleanup function
};
}, [count]); // Dependency arraygraph TD
A[useEffect] --> B{Dependency Array}
B -->|None| C[Execute on every render]
B -->|Empty []| D[Execute only on mount]
B -->|With values| E[Execute when dependencies change]window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
function useWindowSize() {
const [size, setSize] = useState({
width: window.innerWidth,
height: window.innerHeight
});
useEffect(() => {
const handleResize = () => {
setSize({
width: window.innerWidth,
height: window.innerHeight
});
};
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
return size;
}
eslint-plugin-react-hookseslint-plugin-react-hooksundefined| 问题 | 解决方案 |
|---|---|
| 材料不足导致内容单薄 | 使用模型内化知识补充,保持客观 |
| 不同材料观点冲突 | 明确标注不同观点,保持中立 |
| 代码示例无法运行 | 验证代码完整性,添加环境说明 |
| 图片链接失效 | 使用稳定的官方资源URL |
| 文档结构不统一 | 参考标准模板检查 |
| Issue | Solution |
|---|---|
| Thin content due to insufficient materials | Use the model's internalized knowledge to supplement, remain objective |
| Conflicting viewpoints from different materials | Clearly mark different viewpoints, remain neutral |
| Unrunable code examples | Verify code completeness, add environment descriptions |
| Invalid image links | Use stable official resource URLs |
| Inconsistent document structure | Check against the standard template |