I'm looking for a clean way to store several simple values in a custom react hook. It feels uncomfortable to have to return multple setters and getters. I could pass in one value for each, that is const modalState = useState(false) then reference modalState[0] and [1] but that feels odd to. What I don't like about my function below is it returns 10 values. That seems like a lot.
function useNotesModal() {
const [showModal, setShowModal] = useState(false);
const [modalNoteId, setModalNoteId] = useState(0); // if 0, means create note in modal
const [modalNoteTitle, setModalNoteTitle] = useState("");
const [modalNoteDescription, setModalNoteDescription] = useState("");
const [modalNoteTagIds, setModalNoteTagIds] = useState([]);
return {
showModal,
setShowModal,
modalNoteId,
setModalNoteId,
modalNoteTitle,
setModalNoteTitle,
modalNoteDescription,
setModalNoteDescription,
modalNoteTagIds,
setModalNoteTagIds,
};
}
export default useNotesModal;