mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
refactor: moved out reducer to improve memory usage
This commit is contained in:
parent
893153141a
commit
cc57c2aed9
@ -1,10 +1,9 @@
|
||||
import { useReducer, Reducer } from 'react';
|
||||
|
||||
const toggleReducer = (state: boolean, nextValue?: any) => (typeof nextValue === 'boolean' ? nextValue : !state);
|
||||
|
||||
const useToggle = (initialValue: boolean): [boolean, (nextValue?: any) => void] => {
|
||||
return useReducer<Reducer<boolean, any>>(
|
||||
(state: boolean, nextValue?: any) => (typeof nextValue === 'boolean' ? nextValue : !state),
|
||||
initialValue
|
||||
);
|
||||
return useReducer<Reducer<boolean, any>>(toggleReducer, initialValue);
|
||||
};
|
||||
|
||||
export default useToggle;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user