title: How to listen redux state changes in react hooks?
body: <p>I have multiple forms and buttons which user can edit now I would like to display a button save if the state of redux changes.</p>
  <p>live demo : <a href="https://codesandbox.io/s/multiple-inputs-kkm6l?file=/src/Components/Settings.js" rel="nofollow noreferrer">display button save when the state changes</a></p>
  <p>Here is my redux.</p>
  <pre><code>const initialState = {
    firstName: &quot;Kunta &quot;,
    lastName: &quot;Kinte&quot;,
    age: 35,
    country: &quot;Ghana&quot;,
    color: &quot;#000&quot;
  };
  
  const DetailsReducer = (state = initialState, action) =&gt; {
    const { name, value } = action;
  
    return { ...state, [name]: value };
  };
  
  export default DetailsReducer;
  </code></pre>
  <p>Here is my js code to show save button if there is a change in redux state</p>
  <pre><code>    import React, { useState, useEffect } from &quot;react&quot;;
      import { useSelector, useDispatch } from &quot;react-redux&quot;;
      
      const Settings = () =&gt; {
        const fields = useSelector((state) =&gt; state);
        const dispatch = useDispatch();
        const [saveBtn, setSaveBtn] = useState(false);
      
        useEffect(() =&gt; {
          setSaveBtn(true); // show save btn if there is changes in state
        }, []);
      
        console.log(fields.firstName);
      
        return (
          &lt;div&gt;
            &lt;div&gt;
              &lt;h1&gt;Edit &lt;/h1&gt;
              First Name:{&quot; &quot;}
              &lt;input
                name=&quot;firstname&quot;
                value={fields.firstName}
                onChange={(e) =&gt;
                  dispatch({ name: &quot;firstName&quot;, value: e.target.value, type: &quot;&quot; })
                }
              /&gt;
              {saveBtn === true &amp;&amp; &lt;button className=&quot;btn-save&quot;&gt;save &lt;/button&gt;}
            &lt;/div&gt;
          &lt;/div&gt;
        );
      };
      
      export default Settings;
  
  
    [1]: https://codesandbox.io/s/multiple-inputs-kkm6l?file=/src/Components/Settings.js:0-816
  </code></pre>
  <p>What do I need to do to solve this problem.?</p>