How to use the easy-peasy.useStoreActions function in easy-peasy

To help you get started, we’ve selected a few easy-peasy 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 pterodactyl / panel / resources / scripts / components / elements / ProgressBar.tsx View on Github external
export default () => {
    const interval = useRef(null);
    const timeout = useRef(null);
    const [ visible, setVisible ] = useState(false);
    const progress = useStoreState(state => state.progress.progress);
    const continuous = useStoreState(state => state.progress.continuous);
    const setProgress = useStoreActions(actions => actions.progress.setProgress);

    useEffect(() => {
        return () => {
            timeout.current && clearTimeout(timeout.current);
            interval.current && clearInterval(interval.current);
        };
    }, []);

    useEffect(() => {
        setVisible((progress || 0) > 0);

        if (progress === 100) {
            // @ts-ignore
            timeout.current = setTimeout(() => setProgress(undefined), 500);
        }
    }, [ progress ]);
github ctrlplusb / easy-peasy / src / __tests__ / typescript / hooks.ts View on Github external
actionImp: Action;
  actionNoPayload: Action;
  thunkImp: Thunk;
  reducerImp: Reducer;
  nested: {
    actionImp: Action;
    thunkImp: Thunk;
  };
}

let dispatch = useStoreDispatch();
dispatch({ type: 'FOO' });

let useStoreResult = useStoreState((state: State) => state.stateNumber);
useStoreResult + 1;
let useActionResult = useStoreActions(
  (actions: Actions) => actions.actionImp,
);
useActionResult(1);

let store = useStore();
store.getState().stateString + 'world';

const typedHooks = createTypedHooks();

useStoreResult = typedHooks.useStoreState(state => state.stateNumber);
useStoreResult + 1;
useActionResult = typedHooks.useStoreActions(actions => actions.actionImp);
useActionResult(1);
dispatch = typedHooks.useStoreDispatch();
dispatch({
  type: 'FOO',
github pterodactyl / panel / resources / scripts / components / dashboard / forms / DisableTwoFactorModal.tsx View on Github external
export default ({ ...props }: RequiredModalProps) => {
    const { addError, clearFlashes } = useStoreActions((actions: Actions) => actions.flashes);
    const updateUserData = useStoreActions((actions: Actions) => actions.user.updateUserData);

    const submit = ({ password }: Values, { setSubmitting }: FormikHelpers) => {
        clearFlashes('account:two-factor');
        disableAccountTwoFactor(password)
            .then(() => {
                updateUserData({ useTotp: false });
                props.onDismissed();
            })
            .catch(error => {
                console.error(error);

                addError({ message: httpErrorToHuman(error), key: 'account:two-factor' });
                setSubmitting(false);
            });
    };
github wbkd / react-starter / src / containers / App / index.js View on Github external
const App = () => {
  const loadData = useStoreActions(actions => actions.data.loadData);
  const isLoading = useStoreState(state => state.data.isLoading);
  const data = useStoreState(state => state.data.data);

  return (
    
      <button>Load Data</button>
      
    
  );
};