I'm setting up testing for my React app using Vitest + React Testing Library. I'm not sure about best practices:
vi.mock()?Looking for practical examples, not just "test behavior not implementation."
Lena Müller
asked 1 months ago1
Answers114
Upvotes4100
ViewsMy component keeps re-rendering infinitely. Here's a simplified version:
function MyComponent({ onUpdate }) {
const [data, setData] = useState(null);
useEffect(() => {
fetchSomething().then(setData);
onUpdate(data);
}, [onUpdate, data]);
}
I think the issue is with onUpdate but I'm not sure. What are the rules for the dependency array?
I've been using async/await in my Node.js app but I keep running into unhandled promise rejections. Here's my current code:
async function fetchData() {
const res = await fetch('https://api.example.com/data');
const json = await res.json();
return json;
}
What's the correct pattern for catching errors? Should I use try/catch everywhere or is there a better approach?
I'm implementing JWT-based auth in a Next.js app. I've read conflicting advice about where to store the JWT:
What's the recommended approach in 2024 for a production app? Does it change if I'm using NextAuth?
2
Answers88
Upvotes7800
Views2
Answers92
Upvotes4230
ViewsYuki Tanaka
asked 4 months ago2
Answers69
Upvotes15300
Views