@@ -6,59 +6,57 @@ import { useMemo } from 'react'
66/**
77 * A hook to bind action creators to the redux store's `dispatch` function
88 * similar to how redux's `bindActionCreators` works.
9- *
9+ *
1010 * Supports passing a single action creator, an array/tuple of action
1111 * creators, or an object of action creators.
12- *
12+ *
1313 * Any arguments passed to the created callbacks are passed through to
14- * the your functions.
15- *
14+ * your functions.
15+ *
1616 * This hook takes a dependencies array as an optional second argument,
1717 * which when passed ensures referential stability of the created callbacks.
18- *
18+ *
1919 * @param {Function|Function[]|Object.<string, Function> } actions the action creators to bind
2020 * @param {any[] } deps (optional) dependencies array to control referential stability
21- *
21+ *
2222 * @returns {Function|Function[]|Object.<string, Function> } callback(s) bound to store's `dispatch` function
2323 *
24- * Usage:
24+ * @example
2525 *
26- ```jsx
27- import React from 'react'
28- import { useActions } from 'react-redux'
29-
30- const increaseCounter = ({ amount }) => ({
31- type: 'increase-counter',
32- amount,
33- })
34-
35- export const CounterComponent = ({ value }) => {
36- // supports passing an object of action creators
37- const { increaseCounterByOne, increaseCounterByTwo } = useActions({
38- increaseCounterByOne: () => increaseCounter(1),
39- increaseCounterByTwo: () => increaseCounter(2),
40- }, [])
41-
42- // supports passing an array/tuple of action creators
43- const [increaseCounterByThree, increaseCounterByFour] = useActions([
44- () => increaseCounter(3),
45- () => increaseCounter(4),
46- ], [])
47-
48- // supports passing a single action creator
49- const increaseCounterBy5 = useActions(() => increaseCounter(5), [])
50-
51- // passes through any arguments to the callback
52- const increaseCounterByX = useActions(x => increaseCounter(x), [])
53-
54- return (
55- <div>
56- <span>{value}</span>
57- <button onClick={increaseCounterByOne}>Increase counter by 1</button>
58- </div>
59- )
60- }
61- ```
26+ * import React from 'react'
27+ * import { useActions } from 'react-redux'
28+ *
29+ * const increaseCounter = amount => ({
30+ * type: 'increase-counter',
31+ * amount,
32+ * })
33+ *
34+ * export const CounterComponent = ({ value }) => {
35+ * // supports passing an object of action creators
36+ * const { increaseCounterByOne, increaseCounterByTwo } = useActions({
37+ * increaseCounterByOne: () => increaseCounter(1),
38+ * increaseCounterByTwo: () => increaseCounter(2),
39+ * }, [])
40+ *
41+ * // supports passing an array/tuple of action creators
42+ * const [increaseCounterByThree, increaseCounterByFour] = useActions([
43+ * () => increaseCounter(3),
44+ * () => increaseCounter(4),
45+ * ], [])
46+ *
47+ * // supports passing a single action creator
48+ * const increaseCounterBy5 = useActions(() => increaseCounter(5), [])
49+ *
50+ * // passes through any arguments to the callback
51+ * const increaseCounterByX = useActions(x => increaseCounter(x), [])
52+ *
53+ * return (
54+ * <div>
55+ * <span>{value}</span>
56+ * <button onClick={increaseCounterByOne}>Increase counter by 1</button>
57+ * </div>
58+ * )
59+ * }
6260 */
6361export function useActions ( actions , deps ) {
6462 invariant ( actions , `You must pass actions to useActions` )
0 commit comments