<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: christian0125</title>
    <description>The latest articles on DEV Community by christian0125 (@seagullschristian).</description>
    <link>https://dev.to/seagullschristian</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F650761%2F0dc63e1d-0b75-4a83-85fa-850f0badb409.jpg</url>
      <title>DEV Community: christian0125</title>
      <link>https://dev.to/seagullschristian</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/seagullschristian"/>
    <language>en</language>
    <item>
      <title>Answer: How can I re-call API in case of axios intercepter error</title>
      <dc:creator>christian0125</dc:creator>
      <pubDate>Sat, 23 Jul 2022 15:57:09 +0000</pubDate>
      <link>https://dev.to/seagullschristian/answer-how-can-i-re-call-api-in-case-of-axios-intercepter-error-48d6</link>
      <guid>https://dev.to/seagullschristian/answer-how-can-i-re-call-api-in-case-of-axios-intercepter-error-48d6</guid>
      <description>&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;div class="ltag__stackexchange--header"&gt;
          &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Gn-iPj_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
          &lt;a href="https://stackoverflow.com/questions/72998550/how-can-i-re-call-api-in-case-of-axios-intercepter-error/73091824#73091824" rel="noopener noreferrer"&gt;
            &lt;span class="title-flare"&gt;answer&lt;/span&gt; re: How can I re-call API in case of axios intercepter error
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Jul 23 '22&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/72998550/how-can-i-re-call-api-in-case-of-axios-intercepter-error/73091824#73091824" rel="noopener noreferrer"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y9mJpuJP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          0
        &lt;/div&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wif5Zq3z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;After some days of investigating my code, I finally found the answer.&lt;/p&gt;
&lt;p&gt;Let me write my code and hope it will be helpful.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
let refreshToken
if (tokenParts.exp &amp;gt; now) {
            try {
                if (!refreshToken) {
                    refreshToken = service.post('/authentication/token/refresh/', {refresh: refresh_token}).then(token =&amp;gt; {
                        refreshToken = null;
                        return token;
                    });
                }&lt;/code&gt;&lt;/pre&gt;…
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    &lt;a href="https://stackoverflow.com/questions/72998550/how-can-i-re-call-api-in-case-of-axios-intercepter-error/73091824#73091824" class="ltag__stackexchange--btn" rel="noopener noreferrer"&gt;Open Full Answer&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>How can I re-call API in case of axios intercepter error</title>
      <dc:creator>christian0125</dc:creator>
      <pubDate>Sat, 16 Jul 2022 22:12:56 +0000</pubDate>
      <link>https://dev.to/seagullschristian/how-can-i-re-call-api-in-case-of-axios-intercepter-error-23lp</link>
      <guid>https://dev.to/seagullschristian/how-can-i-re-call-api-in-case-of-axios-intercepter-error-23lp</guid>
      <description>&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;div class="ltag__stackexchange--header"&gt;
          &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Gn-iPj_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
          &lt;a href="https://stackoverflow.com/questions/72998550/how-can-i-re-call-api-in-case-of-axios-intercepter-error" rel="noopener noreferrer"&gt;
            How can I re-call API in case of axios intercepter error
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Jul 15 '22&lt;/span&gt;
            &lt;span&gt;Comments: 1&lt;/span&gt;
            &lt;span&gt;Answers: 0&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/72998550/how-can-i-re-call-api-in-case-of-axios-intercepter-error" rel="noopener noreferrer"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y9mJpuJP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          1
        &lt;/div&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wif5Zq3z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;I am developing react project using JWT authentication and write this code.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const service = axios.create({
  baseURL: API_BASE_URL
  timeout: 60000
});

service.interceptors.response.use( (response) =&amp;gt; {
    return response.data
}, async (error) =&amp;gt; {

        const originalRequest = error.config;
    
    // Remove token and redirect 
    if (error.response.status === 400 || error.response.status === 403) {&lt;/code&gt;&lt;/pre&gt;…
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    &lt;a href="https://stackoverflow.com/questions/72998550/how-can-i-re-call-api-in-case-of-axios-intercepter-error" class="ltag__stackexchange--btn" rel="noopener noreferrer"&gt;Open Full Question&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>When to use Object.assign(), spread operator for array state of React app.</title>
      <dc:creator>christian0125</dc:creator>
      <pubDate>Sat, 07 Aug 2021 15:46:25 +0000</pubDate>
      <link>https://dev.to/seagullschristian/when-to-use-object-assign-spread-operator-for-array-state-of-react-app-3bdm</link>
      <guid>https://dev.to/seagullschristian/when-to-use-object-assign-spread-operator-for-array-state-of-react-app-3bdm</guid>
      <description>&lt;p&gt;I have a functional react component which receives a random message object regularly. It displays the new added item properly. After I delete one item and received a new message, deleted item remains again. I solved by using Object.assign(), but not sure why spread operator is not working.&lt;/p&gt;

&lt;p&gt;I think spread operator copies array. I have been using spread operator when adding new item to array state variable. When to use Object.assign(), when to use spread operator?&lt;/p&gt;

&lt;p&gt;Here is my code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myComp = props =&amp;gt; {
  const [messages, setMessages] = useState([]);
  const [api] = useState(new Api({
    messageCallback: (msg) =&amp;gt; {
      handleCallback(msg);
    },
  }));

  useEffect(()=&amp;gt;{
    api.start();
  },[])

  const handleCallback = msg =&amp;gt; {
    messages.push(msg);
    setMessages([...messages]);
  }

  const deleteItem = index =&amp;gt; {
    messages.splice(index,1);
    setMessages([...messages]);
  }

  return (
    &amp;lt;div&amp;gt;
      {
        messages.map((item, index)=&amp;gt;(
          &amp;lt;p key={index} onClick={(e)=&amp;gt;deleteItem(index)}&amp;gt;{item.message}&amp;lt;/p&amp;gt;
        ))
      }
    &amp;lt;/div&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works not properly so I solved by using this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handleCallback = msg =&amp;gt; {
  const temp = Object.assign(messages,[]);
  temp.push(msg);
  setMessages(temp)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In general, many developers are adding a new item by the DOM event. In my app, it is automatically added by the API without rendering the UI. That was the problem. &lt;a href="https://thecodebarbarian.com/object-assign-vs-object-spread.html"&gt;https://thecodebarbarian.com/object-assign-vs-object-spread.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Spread operator also copies the array but have different value though original value changes. When you use Object.assign, copied value has the same value when original value changes.&lt;/p&gt;

&lt;p&gt;In my app, when I use spread operator, message variable remains the original empty value though it seems to change.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
    </item>
  </channel>
</rss>
