How to use unstated-next - 3 common examples

To help you get started, we’ve selected a few unstated-next 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 Flexget / webui / src / plugins / lists / base / hooks / list.ts View on Github external
export const useGetLists = () => {
  const [, dispatch] = useContainer(ListContainer);

  const {
    api: {
      list: { useGet },
    },
  } = usePluginContainer();

  const [state, request] = useGet();
  // Fetch Lists
  useEffect(() => {
    const fn = async () => {
      const resp = await request();

      if (resp.ok) {
        dispatch(actions.getLists(resp.data));
      }
github Flexget / webui / src / core / status / hooks / index.ts View on Github external
export const useGlobalStatus = (loading: boolean, error?: Error) => {
  const id = useRef(uuid());
  const [, dispatch] = useContainer(StatusContainer);

  useEffect(() => {
    if (error) {
      dispatch(actions.pushError(error));
    }
    dispatch(actions.setLoading(id.current, loading));
  }, [dispatch, error, loading]);
};
github Flexget / webui / src / plugins / lists / base / hooks / entry.ts View on Github external
const useRemoveSingleEntry = (entryId?: number) => {
  const [{ listId }] = useContainer(ListContainer);
  const [, dispatch] = useContainer(EntryContainer);
  const {
    api: {
      entry: { useRemove },
    },
  } = usePluginContainer();
  const [state, request] = useRemove(listId, entryId);

  const removeEntry = useCallback(async () => {
    const resp = await request();
    if (resp.ok && entryId) {
      dispatch(actions.removeEntry(entryId));
    }

    return resp;
  }, [dispatch, entryId, request]);

unstated-next

200 bytes to never think about React state management libraries ever again

MIT
Latest version published 5 years ago

Package Health Score

45 / 100
Full package analysis

Popular unstated-next functions

Similar packages