Added shared grid context and moved away from calling useContext directly
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
import { useEffect, useContext } from "react";
|
||||
|
||||
import KeyboardContext from "../contexts/KeyboardContext";
|
||||
|
||||
/**
|
||||
* @param {KeyboardEvent} onKeyDown
|
||||
* @param {KeyboardEvent} onKeyUp
|
||||
*/
|
||||
function useKeyboard(onKeyDown, onKeyUp) {
|
||||
const { keyEmitter } = useContext(KeyboardContext);
|
||||
useEffect(() => {
|
||||
if (onKeyDown) {
|
||||
keyEmitter.on("keyDown", onKeyDown);
|
||||
}
|
||||
if (onKeyUp) {
|
||||
keyEmitter.on("keyUp", onKeyUp);
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (onKeyDown) {
|
||||
keyEmitter.off("keyDown", onKeyDown);
|
||||
}
|
||||
if (onKeyUp) {
|
||||
keyEmitter.off("keyUp", onKeyUp);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export default useKeyboard;
|
||||
@@ -1,16 +1,14 @@
|
||||
import { useContext } from "react";
|
||||
|
||||
import get from "lodash.get";
|
||||
import set from "lodash.set";
|
||||
|
||||
import SettingsContext from "../contexts/SettingsContext";
|
||||
import { useSettings } from "../contexts/SettingsContext";
|
||||
|
||||
/**
|
||||
* Helper to get and set nested settings that are saved in local storage
|
||||
* @param {String} path The path to the setting within the Settings object provided by the SettingsContext
|
||||
*/
|
||||
function useSetting(path) {
|
||||
const { settings, setSettings } = useContext(SettingsContext);
|
||||
const { settings, setSettings } = useSettings();
|
||||
|
||||
const setting = get(settings, path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user