qkreltms / react-action-listener

Middleware, React hook which allows making side effect and listening actions of Context or Redux
MIT License
9 stars 0 forks source link

Cannot listen action list when passing it by props #51

Open qkreltms opened 3 years ago

qkreltms commented 3 years ago

Describe the bug Cannot listen list actions when it provided by props. To Reproduce

import React, { useState } from "react";
import { useActionListener } from "react-action-listener";

const ListenMultipleAction = (actions) => {
   //1. get listening actions by props
  const [callNum, setCallNum] = useState(0);

  useActionListener(actions, () => {
    setCallNum((num) => num + 1);
  });

  return (
    <>
      <h3>All action dispatched cnt: {callNum}</h3>
    </>
  );
};

export default ListenMultipleAction;

<ListenMultipleAction actions={["ADD", "SUB", "P_SUB", "P_ADD"]} />

// 2. Now dispatch 'ADD'
// 3. Nothing happens

Additional context It due to ['actions'] !== ['actions'] in useActionListener

qkreltms commented 3 years ago

https://github.com/facebook/react/issues/14476#issuecomment-471199055