<?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: mrarthurwhite</title>
    <description>The latest articles on DEV Community by mrarthurwhite (@mrarthurwhite).</description>
    <link>https://dev.to/mrarthurwhite</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%2F658414%2F434cd6a6-b0b3-4dd3-9f66-53d5e7b0e01e.png</url>
      <title>DEV Community: mrarthurwhite</title>
      <link>https://dev.to/mrarthurwhite</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mrarthurwhite"/>
    <language>en</language>
    <item>
      <title>Variable Undefined For Simple Demo App</title>
      <dc:creator>mrarthurwhite</dc:creator>
      <pubDate>Tue, 29 Jun 2021 11:41:42 +0000</pubDate>
      <link>https://dev.to/mrarthurwhite/variable-undefined-for-simple-demo-app-1o94</link>
      <guid>https://dev.to/mrarthurwhite/variable-undefined-for-simple-demo-app-1o94</guid>
      <description>&lt;p&gt;Dear kind, empathetic, helpful members of the forum,&lt;/p&gt;

&lt;p&gt;I am writing a straightforward react app with a very basic api (git hub repo : &lt;a href="https://github.com/mrarthurwhite/use_effect_react_hooks_demo"&gt;https://github.com/mrarthurwhite/use_effect_react_hooks_demo&lt;/a&gt;). Following is the functional component which is a demo component meant to illustrate a fetch (with axios), using the &lt;code&gt;useEffect&lt;/code&gt; hook, followed by just displaying the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import './App.css';
import React, {  useEffect, useState } from 'react';
import axios from 'axios';

function GetWordsWAxiosNLoading() {
  const [words, setWords] = useState([]);
  let isLoading = false;

  console.log("isLoading prefetch " + isLoading); 

  async function fetchData(){
    isLoading = true;
    console.log("isLoading fetching " + isLoading); 
    let url = 'http://localhost:1111/wordlist';
    const result= await axios(url);
    setWords(result.data);
    isLoading = false;
    console.log("isLoading resetting " + isLoading); 
  };

  useEffect(() =&amp;gt; {fetchData()}, [] );
  console.log("isLoading postfetch " + isLoading); 
    return (
    &amp;lt;&amp;gt;
    { isLoading? (&amp;lt;div&amp;gt;Loading . . . &amp;lt;/div&amp;gt;) : (     {words.map(w=&amp;gt; &amp;lt;div&amp;gt;{w.word}&amp;lt;/div&amp;gt;)}    ) }
    &amp;lt;/&amp;gt;
  );
}

export default GetWordsWAxiosNLoading;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The error I am getting is :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./src/GetWordsWAxiosNLoading.js
SyntaxError: use_effect_react_hooks_demo/use_effect_initial_demo/src/GetWordsWAxiosNLoading.js: Unexpected token (27:59)

  25 |     return (
  26 |     &amp;lt;&amp;gt;
&amp;gt; 27 |     { isLoading? (&amp;lt;div&amp;gt;Loading . . . &amp;lt;/div&amp;gt;) : (     {words.map(w=&amp;gt; &amp;lt;div&amp;gt;{w.word}&amp;lt;/div&amp;gt;)}    ) }
     |                                                            ^
  28 |     &amp;lt;/&amp;gt;
  29 |   );
  30 | }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At line 27 above it is giving both a &lt;code&gt;Line 27:60:  Parsing error: Unexpected token&lt;/code&gt; &amp;amp; a &lt;code&gt;SyntaxError&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I have working variants of the above :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;where I am just using &lt;code&gt;fetch&lt;/code&gt; instead of &lt;code&gt;axios&lt;/code&gt; httpclient (&lt;a href="https://github.com/mrarthurwhite/use_effect_react_hooks_demo/blob/master/use_effect_initial_demo/src/App.js"&gt;https://github.com/mrarthurwhite/use_effect_react_hooks_demo/blob/master/use_effect_initial_demo/src/App.js&lt;/a&gt;), &amp;amp; it works fine now.&lt;/li&gt;
&lt;li&gt;where I am using axios but without a &lt;code&gt;loading&lt;/code&gt; variable ( &lt;a href="https://github.com/mrarthurwhite/use_effect_react_hooks_demo/blob/master/use_effect_initial_demo/src/GetWordsWAxios.js"&gt;https://github.com/mrarthurwhite/use_effect_react_hooks_demo/blob/master/use_effect_initial_demo/src/GetWordsWAxios.js&lt;/a&gt;) &amp;amp; it works fine now but it was also giving errors with &lt;code&gt;words&lt;/code&gt; being undefined initially.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The issues are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;there are no console log outputs&lt;/li&gt;
&lt;li&gt;the &lt;code&gt;isLoading&lt;/code&gt; variable is undefined (I was initially using &lt;code&gt;isLoadings&lt;/code&gt; a variable stored in the &lt;code&gt;state&lt;/code&gt; object but decided to simplify it).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Any ideas as to what could be going on? &lt;br&gt;
Thanks in advance!&lt;/p&gt;

</description>
      <category>react</category>
      <category>hooks</category>
      <category>axios</category>
    </item>
  </channel>
</rss>
