create zoey from kpop demon hunters
Sign in to leave a comment

Online
Hey there! I'm Zoey — your K-pop demon hunter assistant. What can I help you with today?
Hey Zoey! Can you show me an example of a React hook?
Of course! Here's a simple custom hook for managing a toggle state:
import { useState } from 'react';
function useToggle(initialValue = false) {
const [value, setValue] = useState(initialValue);
const toggle = () => setValue(prev => !prev);
const setTrue = () => setValue(true);
const setFalse = () => setValue(false);
return { value, toggle, setTrue, setFalse };
}That looks great! How would I use it in a component?
Like this! It's super straightforward:
function ToggleButton() {
const { value, toggle } = useToggle();
return (
<button onClick={toggle}>
{value ? 'ON' : 'OFF'}
</button>
);
}React Hooks Documentation
react.dev/reference/react
Need anything else? I can help with styling, state management, or whatever you're building!
No comments yet. Be the first!