This is test blog to test if the mdx file is rendering correctly
Introduction
Artificial Intelligence (AI) is revolutionizing the way developers write code. From auto-completing functions to generating entire applications, AI-powered tools like GitHub Copilot and OpenAI’s GPT models are changing the software development landscape.
How AI Understands Code
Modern AI models are trained on vast amounts of code from repositories like GitHub and Stack Overflow. Using deep learning and transformer architectures, these models analyze patterns, predict the next lines of code, and even detect bugs before execution.
Benefits of AI in Development
- Increased Productivity – AI helps developers write code faster by suggesting boilerplate and refactoring existing code.
- Error Reduction – Intelligent AI systems catch syntax errors and security vulnerabilities in real time.
- Learning & Assistance – AI acts as a coding assistant, helping developers learn new frameworks and languages.
AI is transforming how we write code, but it’s a tool, not a replacement for developers. The best approach is to leverage AI for efficiency while maintaining critical thinking and domain expertise.
import React, { useState, useEffect, useCallback } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import PropTypes from 'prop-types';
import './styles.css';
// A custom hook for handling window resize
const useWindowSize = () => {
const [windowSize, setWindowSize] = useState({
width: undefined,
height: undefined,
});
useEffect(() => {
// Handler to call on window resize
function handleResize() {
setWindowSize({
width: window.innerWidth,
height: window.innerHeight,
});
}
// Add event listener
window.addEventListener("resize", handleResize);
// Call handler right away so state gets updated with initial window size
handleResize();
// Remove event listener on cleanup
return () => window.removeEventListener("resize", handleResize);
}, []); // Empty array ensures that effect is only run on mount and unmount
return windowSize;
}
// A TodoItem component with JSX
const TodoItem = ({ todo, onToggle, onDelete }) => (
<motion.li
initial={{ opacity: 0, y: -10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: 10 }}
className={`todo-item ${todo.completed ? 'completed' : ''}`}
>
<input
type="checkbox"
checked={todo.completed}
onChange={() => onToggle(todo.id)}
/>
<span>{todo.text}</span>
<button onClick={() => onDelete(todo.id)}>Delete</button>
</motion.li>
);
TodoItem.propTypes = {
todo: PropTypes.shape({
id: PropTypes.number.isRequired,
text: PropTypes.string.isRequired,
completed: PropTypes.bool.isRequired,
}).isRequired,
onToggle: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired,
};
// Main TodoApp component
function TodoApp() {
const [todos, setTodos] = useState([]);
const [inputValue, setInputValue] = useState('');
const { width } = useWindowSize();
const handleAddTodo = (e) => {
e.preventDefault();
if (!inputValue.trim()) return;
const newTodo = {
id: Date.now(),
text: inputValue,
completed: false,
};
setTodos([...todos, newTodo]);
setInputValue('');
};
const handleToggle = useCallback((id) => {
setTodos(todos.map(todo =>
todo.id === id ? { ...todo, completed: !todo.completed } : todo
));
}, [todos]);
const handleDelete = useCallback((id) => {
setTodos(todos.filter(todo => todo.id !== id));
}, [todos]);
const completedCount = todos.filter(todo => todo.completed).length;
return (
<div className="todo-app">
<h1>React Todo App</h1>
{width < 768 && <p>Mobile view detected</p>}
<form onSubmit={handleAddTodo}>
<input
type="text"
value={inputValue}
onChange={e => setInputValue(e.target.value)}
placeholder="Add a new todo..."
/>
<button type="submit">Add</button>
</form>
<div className="stats">
<p>Total: {todos.length}</p>
<p>Completed: {completedCount}</p>
</div>
<AnimatePresence>
<ul className="todo-list">
{todos.length > 0 ? (
todos.map(todo => (
<TodoItem
key={todo.id}
todo={todo}
onToggle={handleToggle}
onDelete={handleDelete}
/>
))
) : (
<p>No todos yet! Add one above.</p>
)}
</ul>
</AnimatePresence>
</div>
);
}
export default TodoApp;
A sample code
if (pathName === "/keystatic" || pathName?.startsWith("/keystatic/")) {
return null;
}
Yared Yilma
Author