databag/app/mobile/src/context/useDisplayContext.hook.js

31 lines
591 B
JavaScript
Raw Normal View History

2023-09-05 21:20:47 +00:00
import { useEffect, useContext, useState, useRef } from 'react';
export function useDisplayContext() {
const [state, setState] = useState({
2023-09-05 22:49:35 +00:00
prompt: null,
alert: null,
2023-09-05 21:20:47 +00:00
});
const updateState = (value) => {
setState((s) => ({ ...s, ...value }))
}
const actions = {
2023-09-05 22:49:35 +00:00
showPrompt: (prompt) => {
updateState({ prompt });
2023-09-05 21:20:47 +00:00
},
2023-09-05 22:49:35 +00:00
hidePrompt: () => {
updateState({ prompt: null });
},
showAlert: (alert) => {
updateState({ alert });
},
hideAlert: () => {
updateState({ alert: null });
2023-09-05 21:20:47 +00:00
},
};
return { state, actions }
}