How to use the piral-core.useActions function in piral-core

To help you get started, we’ve selected a few piral-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github smapiot / piral / src / packages / piral-translate / src / hooks.ts View on Github external
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),
      )
github smapiot / piral / src / packages / piral / src / hooks / translate.ts View on Github external
export function useTranslate() {
  const { translate } = useActions();
  useGlobalState(m => m.app.language.selected);
  return translate;
}
github smapiot / piral / src / packages / piral-translate / src / hooks.ts View on Github external
export function useTranslate() {
  const { translate } = useActions();
  useGlobalState(m => m.app.language.selected);
  return translate;
}
github smapiot / piral / src / packages / piral-search / src / useSearch.ts View on Github external
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];
}