mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 18:17:38 +00:00
Add useActionCreator hook
This commit is contained in:
parent
3f34e240a3
commit
eaac55e70d
2 changed files with 13 additions and 6 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import * as React from "react";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useActionCreator } from "./hooks";
|
||||
import * as Actions from "./redux/actionCreators";
|
||||
import { SHOW_UPLOAD } from "./constants";
|
||||
import UploadIcon from "./components/icons/UploadIcon";
|
||||
|
|
@ -7,10 +8,7 @@ import CloseIcon from "./components/icons/CloseIcon";
|
|||
|
||||
function UploadButton() {
|
||||
const uploadViewOpen = useSelector((state) => state.uploadViewState);
|
||||
const dispatch = useDispatch();
|
||||
function toggleUploadView() {
|
||||
dispatch(Actions.toggleUploadView());
|
||||
}
|
||||
const toggleUploadView = useActionCreator(Actions.toggleUploadView);
|
||||
if (!SHOW_UPLOAD) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
11
src/hooks.js
11
src/hooks.js
|
|
@ -1,5 +1,6 @@
|
|||
import * as Utils from "./utils";
|
||||
import { useMemo, useState, useEffect } from "react";
|
||||
import { useMemo, useState, useEffect, useCallback } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
|
||||
export function useWindowSize() {
|
||||
const [windowSize, setWindowSize] = useState(Utils.getWindowSize());
|
||||
|
|
@ -38,3 +39,11 @@ export function useScrollbarWidth() {
|
|||
return scrollbarWidth;
|
||||
}, []);
|
||||
}
|
||||
|
||||
export function useActionCreator(actionCreator) {
|
||||
const dispatch = useDispatch();
|
||||
return useCallback((...args) => dispatch(actionCreator(...args)), [
|
||||
dispatch,
|
||||
actionCreator,
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue