Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function useDynamicLanguage(
defaultSelected: string,
load: LanguageLoader,
): [string, (language: string) => void] {
const [selected, setSelected] = useState(defaultSelected);
const { selectLanguage, setLoading, setTranslations, getTranslations } = useActions();
useEffect(() => {
let active = true;
const current = getTranslations(selected);
selectLanguage(undefined);
setLoading(true);
load(selected, current)
.then(
result => {
if (active) {
setTranslations(selected, result);
selectLanguage(selected);
}
},
err => console.error(err),
)
export function useTranslate() {
const { translate } = useActions();
useGlobalState(m => m.app.language.selected);
return translate;
}
export function useTranslate() {
const { translate } = useActions();
useGlobalState(m => m.app.language.selected);
return translate;
}
export function useSearch(): [string, (value: string) => void] {
const { setSearchInput, triggerSearch } = useActions();
const searchInput = useGlobalState(m => m.search.input);
const query = useDebounce(searchInput);
const cancel = useRef(undefined);
useEffect(() => {
cancel.current && cancel.current();
cancel.current = triggerSearch(query, false);
}, [query]);
return [searchInput, setSearchInput];
}