title: How to destructure a json object into another json object?
body: <p>My project uses React with Redux. In one of my components, I am getting some data from an API. It looks something like this,</p>
  <pre><code>{
  &quot;refresh&quot;: &quot;some token&quot;,
  &quot;access&quot;: &quot;some token&quot;,
  &quot;isStudent&quot;: true,
  &quot;user&quot;: {
      &quot;username&quot;: &quot;xyz&quot;,
      &quot;first_name&quot;: &quot;xyz&quot;,
      &quot;last_name&quot;: &quot;xyz&quot;,
      &quot;email&quot;: &quot;some email id&quot;,
      &quot;groups&quot;: [
          2
      ],
      &quot;id&quot;: 11
     }
  }
  </code></pre>
  <p>The action for this looks like,</p>
  <pre><code>function login(data) {
   return {
    type: 'LOGIN',
    access: data.access,
    refresh: data.refresh,
    isStudent: data.isStudent,
    username: '',
    first_name: '',
    last_name: '',
    email: '',
   };
  }
  </code></pre>
  <p>The exact json format fetched from the API is passed into <code>data</code> of the action,
  The Redux State has a format like,</p>
  <pre><code> const state = {
    isLogged: false,
    jwt: '',
    refresh: '',
    isStudent: true,
    username: '',
    email: '',
    first_name: '',
    last_name: '',
   };
  </code></pre>
  <p>Can I destructore the <code>data</code> in my action function?
  Something like this,</p>
  <pre><code>function login(data) {
   return {
   type: 'LOGIN',
   access: data.access,
   refresh: data.refresh,
   isStudent: data.isStudent,
   {username,first_name,last_name,email}:data.user,
   };
  }
  </code></pre>