Jesus sucks
This commit is contained in:
28
backend/frontend/node_modules/@restart/hooks/esm/useToggleState.js
generated
vendored
Normal file
28
backend/frontend/node_modules/@restart/hooks/esm/useToggleState.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { useReducer } from 'react';
|
||||
|
||||
/**
|
||||
* Create a state setter pair for a boolean value that can be "switched".
|
||||
* Unlike `useState(false)`, `useToggleState` will automatically flip the state
|
||||
* value when its setter is called with no argument.
|
||||
*
|
||||
* @param initialState The initial boolean value
|
||||
* @returns A tuple of the current state and a setter
|
||||
*
|
||||
* ```jsx
|
||||
* const [show, toggleShow] = useToggleState(false)
|
||||
*
|
||||
* return (
|
||||
* <>
|
||||
* <button onClick={() => toggleShow()}>
|
||||
* Toggle
|
||||
* <button>
|
||||
*
|
||||
* {show && <strong>Now you can see me</strong>}
|
||||
* </>
|
||||
* )
|
||||
*
|
||||
* ```
|
||||
*/
|
||||
export default function useToggleState(initialState = false) {
|
||||
return useReducer((state, action) => action == null ? !state : action, initialState);
|
||||
}
|
||||
Reference in New Issue
Block a user