mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
chrone: sperate client and server to different repos.
This commit is contained in:
36
src/hooks/stackableState.js
Normal file
36
src/hooks/stackableState.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import {useState} from 'react';
|
||||
|
||||
const useStackableState = (initialState = []) => {
|
||||
const [stackableState, setStackableState] = useState(initialState);
|
||||
|
||||
const indexState = (state) => stackableState.indexOf(state);
|
||||
const hasState = (state) => indexState(state) !== -1;
|
||||
|
||||
const removeState = (state) => {
|
||||
if (this.hasState(state)) {
|
||||
const index = indexState(state);
|
||||
const mutableState = [...stackableState];
|
||||
mutableState.splice(index, 1);
|
||||
|
||||
setStackableState(mutableState);
|
||||
}
|
||||
};
|
||||
const setState = (state) => {
|
||||
if (!hasState(state)) {
|
||||
setStackableState([
|
||||
...stackableState,
|
||||
state,
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
state: stackableState,
|
||||
removeState,
|
||||
indexState,
|
||||
hasState,
|
||||
setState,
|
||||
};
|
||||
};
|
||||
|
||||
export default useStackableState;
|
||||
Reference in New Issue
Block a user