-
Before publishing your work into this repo, please create a branch from main branch and commit it into the new created branch.
-
Your hooks must be write in typescript and please clearly define the needed types or interfaces.
-
Before you start writing your custom hook, make sure it is not duplicated, even in logic or functionality.
-
After writing your custom hook, you should write a clear usecase example of your hook in the README.md file.
-
Please pay attention to the first example to understand how to write your hooks usecase examples.
const { width } = useWindowSize();
// return
<div
style={{
width: 300,
height: 300,
backgroundColor: width < 500 ? "red" : "blue",
}}
></div>;const { text, toggle } = useToggleText("default value", "toggled value");
// return
<div style={{ width: 300, height: 300, background: "#ccc" }} onClick={toggle}>
{text}
</div>;const [value, setValue] = useLocalStorage("name");
console.log(value);
// return
<div>
<input
type="text"
placeholder="Enter your name"
value={value}
onChange={(e) => setValue(e.target.value)}
/>
</div>;const camelCasedValue = useCamelCase("john-doe", "-");
console.log(camelCasedValue); // johnDoeconst [prevState, state, setValue] = usePreviousState(0);
// return
<div>
<button onClick={() => setValue(state + 1)}>increase</button>
<span>{prevState}</span> {/* return previous value */}
<span>{state}</span> {/* return current value */}
</div>;