A shared tag with AI prompts and code snippets
From workspace: FreeCodeCamp
Team: Main
Total snippets: 6
6 snippets
Toast notification system with dismiss and delay support.
function Toast({ message, onClose }) { useEffect(() => { const timer = setTimeout(onClose, 3000); return () => clearTimeout(timer); }, []); return <div className="toast">{message}</div>; }
Use React Context API to toggle light/dark theme.
const ThemeContext = createContext(); function ThemeProvider({ children }) { const [theme, setTheme] = useState('light'); const toggleTheme = () => setTheme(t => (t === 'light' ? 'dark' : 'light')); return ( <ThemeContext.Provider...
Simple tab component with active tab state handling.
function Tabs({ tabs }) { const [active, setActive] = useState(0); return ( <div> <div className="tab-buttons"> {tabs.map((t, i) => ( <button key={i} onClick={() => setActive(i)}> {t.label} ...
Reusable button component with props for text, click, and disabled state.
function Button({ label, onClick, disabled }) { return ( <button disabled={disabled} onClick={onClick}> {label} </button> ); }
A basic controlled input with state management in React.
function InputExample() { const [value, setValue] = useState(''); return ( <input value={value} onChange={(e) => setValue(e.target.value)} placeholder="Type something..." /> ); }
A simple reusable modal component using React hooks and portals.
import ReactDOM from 'react-dom'; function Modal({ isOpen, children, onClose }) { if (!isOpen) return null; return ReactDOM.createPortal( <div className="modal-overlay" onClick={onClose}> <div className="modal-content" onClick={e =>...