title: How to pass a localstorage value as an argument in axios request
body: <p>I have a React app and I use Express to handle my db queries.</p>
  <p>What I want is to pass my user id stored in localstorage into a post request.</p>
  <p>(My app is basically a game where users can gain cards to fight against other players, and to do so, I need to update my db when a user receives a card, which is why I'm trying to do the following).
  Here's my code:</p>
  <pre><code>import React, {useEffect, useState} from 'react';
  import Axios from &quot;axios&quot;;
  import axios from &quot;axios&quot;;
  
  const Cards = () =&gt; {
  
  const [card, setCard] = useState([]);
  const id = localStorage.getItem(&quot;id&quot;);
  console.log(id) // Output is 1 (correct)
  
  useEffect(() =&gt; {
      async function fetchData() {
          try {
              // Below, id should refer to localStorage.getItem(&quot;id&quot;)
              const res = await Axios.post('http://localhost:3001/getRandomCard', {id}) 
              setCard(res.data)
          } catch (err) {
              console.log('error:', err)
          }
      }
  
      fetchData()
  }, []);
  
  return (
      &lt;div&gt;
          &lt;div&gt;
              {card.map(aCard =&gt; &lt;div className={&quot;text-center&quot;} key={aCard.name}&gt; {aCard.name}
                  &lt;img alt={&quot;Image de &quot; + aCard.name} className={'activator'} src={'http://localhost/lfl/inc/img/players-ico/' + aCard.name} style={{width: '100%'}}/&gt;
              &lt;/div&gt;)}
          &lt;/div&gt;
  
      &lt;/div&gt;);
  };
  
  export default Cards;
  </code></pre>
  <p>And on my app.js:</p>
  <pre><code>app.post('/getRandomCard', async function (req, res) {
  
      const id = req.params.id;
  
      console.log('userid= ', id) // Output: undefined
  
      // ...
  
  })
  </code></pre>
  <p>I'm very new to React, so I'm trying basic stuff, and maybe my code is not the better way to do what I'm actually trying to do, if so, every comment is deeply appreciated.</p>