refactor: move TypeScript and TSX test code to fixture files

This commit is contained in:
Paul Gauthier (aider) 2024-11-27 07:06:50 -08:00
parent 4580fac6fa
commit 7465b4bf91
3 changed files with 28 additions and 63 deletions

View file

@ -1,11 +1,30 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
interface GreetingProps {
interface UserProps {
name: string;
age?: number;
}
const Greeting: React.FC<GreetingProps> = ({ name }) => {
return <h1>Hello, {name}!</h1>;
// Component with props interface
const UserGreeting: React.FC<UserProps> = ({ name, age }) => {
const [greeting, setGreeting] = useState<string>('');
useEffect(() => {
setGreeting(`Hello, ${name}${age ? ` (${age})` : ''}!`);
}, [name, age]);
return <h1>{greeting}</h1>;
};
export default Greeting;
// Custom hook
function useCounter(initial: number = 0) {
const [count, setCount] = useState(initial);
const increment = () => setCount(c => c + 1);
return { count, increment };
}
// Constants
const DEFAULT_NAME = 'World';
const MAX_AGE = 150;
export { UserGreeting, useCounter, DEFAULT_NAME, MAX_AGE };