You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: demo examples and dark mode issue for grok demo (#83)
* feat: introduce ChatGPT, Claude, and Grok demo examples and update introduction docs page
* chore(docs): add new usage and troubleshooting guides while removing the setup guide
* chore(docs): update components documentation pages
* fix: demo examples and dark mode issue for grok demo
"snippet": "Hooks must be called at the top level of your React function components or custom hooks. Don't call hooks inside loops, conditions, or nested functions."
"snippet": "Reactivity Core is a set of core APIs for creating reactive data in Vue. It provides the basic building blocks for creating reactive data in Vue."
"snippet": "useState is a React Hook that lets you add state to your function components. It returns an array with two values: the current state and a function to update it."
"snippet": "useEffect lets you synchronize a component with external systems. It runs after render and can be used to perform side effects like data fetching."
React hooks are a powerful feature that let you use state and other React features without writing classes. Here are some tips for using them effectively:
153
-
154
-
## Rules of Hooks
155
-
156
-
1. **Only call hooks at the top level** of your component or custom hooks
157
-
2. **Don't call hooks inside loops, conditions, or nested functions**
158
-
159
-
## Common Hooks
160
-
161
-
- **useState**: For local component state
162
-
- **useEffect**: For side effects like data fetching
163
-
- **useContext**: For consuming context
164
-
- **useReducer**: For complex state logic
165
-
- **useCallback**: For memoizing functions
166
-
- **useMemo**: For memoizing values
167
-
168
-
## Example of useState and useEffect
169
-
170
-
\`\`\`jsx
171
-
function ProfilePage({ userId }) {
172
-
const [user, setUser] = useState(null);
173
-
174
-
useEffect(() => {
175
-
// This runs after render and when userId changes
176
-
fetchUser(userId).then(userData => {
177
-
setUser(userData);
178
-
});
179
-
}, [userId]);
180
-
181
-
return user ? <Profile user={user} /> : <Loading />;
182
-
}
149
+
content: `# Vue Reactivity Best Practices
150
+
151
+
Vue reactivity is a powerful feature that let you use state and other Vue features without writing classes. Here are some tips for using them effectively:
152
+
153
+
## Rules of Reactivity
154
+
155
+
1. **Only call reactivity at the top level** of your component or custom hooks
156
+
2. **Don't call reactivity inside loops, conditions, or nested functions**
157
+
158
+
## Core Reactivity APIs
159
+
160
+
- **ref()** – for primitive reactive values
161
+
- **reactive()** – for objects
162
+
- **computed()** – memoized derived values
163
+
- **watch()** – respond to state changes
164
+
- **watchEffect()** – run effects automatically
165
+
166
+
## Example of ref() and watchEffect()
167
+
168
+
\`\`\`vue
169
+
<script setup>
170
+
import { ref, watchEffect } from "vue";
171
+
172
+
const userId = ref(1);
173
+
const user = ref(null);
174
+
175
+
watchEffect(async () => {
176
+
user.value = await fetchUser(userId.value);
177
+
});
178
+
<\/script>
179
+
180
+
<template>
181
+
<Profile v-if="user" :user="user" />
182
+
<Loading v-else />
183
+
</template>
183
184
\`\`\`
184
185
185
-
Would you like me to explain any specific hook in more detail?`,
186
+
Want deeper explanation of computed() and handling expensive logic?
187
+
`,
186
188
},
187
189
],
188
190
},
@@ -193,85 +195,85 @@ Would you like me to explain any specific hook in more detail?`,
193
195
{
194
196
id: nanoid(),
195
197
content:
196
-
'Yes, could you explain useCallback and useMemo in more detail? When should I use one over the other?',
198
+
'Yes, could you explain computed and function memoization in more detail? When should I use one over the other?',
197
199
},
198
200
{
199
201
id: nanoid(),
200
202
content:
201
-
'I\'m particularly interested in understanding the performance implications of useCallback and useMemo. Could you break down when each is most appropriate?',
203
+
'I\'m particularly interested in understanding the performance implications of computed and memoized functions in Vue. Could you break down when each is most appropriate?',
202
204
},
203
205
{
204
206
id: nanoid(),
205
207
content:
206
-
'Thanks for the overview! Could you dive deeper into the specific use cases where useCallback and useMemo make the biggest difference in React applications?',
208
+
'Thanks for the overview! Could you dive deeper into the specific use cases where computed and memoized functions make the biggest difference in Vue applications?',
207
209
},
208
210
],
209
211
},
210
212
{
211
213
key: nanoid(),
212
214
from: 'assistant',
213
215
reasoning: {
214
-
content: `The user is asking for a detailed explanation of useCallback and useMemo. I should provide a clear and concise explanation of each hook's purpose and how they differ.
215
-
216
-
The useCallback hook is used to memoize functions to prevent unnecessary re-renders of child components that receive functions as props.
216
+
content: `The user is asking for a detailed explanation of how Vue handles memoized values and reactive updates. I should provide a clear and concise explanation of each concept's purpose and how they differ.
217
+
218
+
The computed() function is used to create cached, derived values that only update when their reactive dependencies change.
217
219
218
-
The useMemo hook is used to memoize values to avoid expensive recalculations on every render.
220
+
Regular functions inside setup() rely on Vue’s reactivity system and only run when the state they depend on changes.
219
221
220
-
Both hooks help with performance optimization, but they serve different purposes.`,
222
+
Both features help with performance optimization, but they serve different purposes.`,
221
223
duration: 10,
222
224
},
223
225
versions: [
224
226
{
225
227
id: nanoid(),
226
-
content: `## useCallback vs useMemo
228
+
content: `## computed vs watch
227
229
228
-
Both hooks help with *performance optimization*, but they serve different purposes:
230
+
Both features help with _performance optimization_, but they serve different purposes:
229
231
230
-
### useCallback
232
+
### computed
231
233
232
-
\`useCallback\` memoizes **functions** to prevent unnecessary re-renders of child components that receive functions as props.
234
+
\`computed\` memoizes **derived values** and only updates when their reactive dependencies change.
233
235
234
-
\`\`\`jsx
235
-
// Without useCallback - a new function is created on every render
236
-
const handleClick = () => {
237
-
console.log(count);
238
-
};
236
+
\`\`\`ts
237
+
// A simple reactive state
238
+
const count = ref(0);
239
239
240
-
// With useCallback - the function is only recreated when dependencies change
241
-
const handleClick = useCallback(() => {
242
-
console.log(count);
243
-
}, [count]);
240
+
// Using computed - value is cached until 'count' changes
241
+
const doubled = computed(() => count.value * 2);
244
242
\`\`\`
245
243
246
-
### useMemo
244
+
### watch
247
245
248
-
\`useMemo\`memoizes **values** to avoid expensive recalculations on every render.
246
+
\`watch\`is used to run **side effects** in response to reactive state changes.
249
247
250
-
\`\`\`jsx
251
-
// Without useMemo - expensive calculation runs on every render
252
-
const sortedList = expensiveSort(items);
253
-
254
-
// With useMemo - calculation only runs when items change
0 commit comments