<?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>Forem: Kayut</title>
    <description>The latest articles on Forem by Kayut (@kayut).</description>
    <link>https://forem.com/kayut</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%2F86554%2Ff2dc317c-cc7d-4436-b99a-7a4e354040a1.png</url>
      <title>Forem: Kayut</title>
      <link>https://forem.com/kayut</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kayut"/>
    <language>en</language>
    <item>
      <title>Which react-redux-thunk boilerplate do you recommend?</title>
      <dc:creator>Kayut</dc:creator>
      <pubDate>Tue, 05 Mar 2019 13:49:25 +0000</pubDate>
      <link>https://forem.com/kayut/which-react-redux-thunk-boilerplate-do-you-recommend-9p2</link>
      <guid>https://forem.com/kayut/which-react-redux-thunk-boilerplate-do-you-recommend-9p2</guid>
      <description>&lt;p&gt;&lt;strong&gt;creact-create-app&lt;/strong&gt; is a great starting point for creating a react app, but once you need to add &lt;strong&gt;react-redux&lt;/strong&gt; to your project, you have to write a lot of code and repeat this in each project again and again.&lt;/p&gt;

&lt;p&gt;I wish there was a create-react-app command that could create an app which includes also the react-redux parts such as a store file, a reducer folder with an index.js in it, action, thunk etc.&lt;/p&gt;

&lt;p&gt;Or is there any good boilerplate, which I can use? Which boilerplate do you recommend?&lt;/p&gt;

&lt;p&gt;What do you do to minimise writing repetitive code in a react-redux project?&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React project on GoDaddy server</title>
      <dc:creator>Kayut</dc:creator>
      <pubDate>Mon, 18 Feb 2019 12:14:19 +0000</pubDate>
      <link>https://forem.com/kayut/react-project-on-godaddy-server-16c0</link>
      <guid>https://forem.com/kayut/react-project-on-godaddy-server-16c0</guid>
      <description>&lt;p&gt;Just built my very first react app and uploaded it to my GoDaddy server.&lt;/p&gt;

&lt;p&gt;These are the uploaded files:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.stack.imgur.com/lrmUL.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PGq_Y7Ib--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.stack.imgur.com/lrmUL.png" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But now, if I try to open my react project in browser, it doesn't work at all and I only see a blank page with the following errors in console:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.stack.imgur.com/Ig2me.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jT0t5W2I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.stack.imgur.com/Ig2me.png" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I double checked, and those css files are existing inside the static folder. Why do they produce 404 error?&lt;br&gt;
Am I missing something? Does a React app need special settings on external server?&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>React and Axios - How to avoid 404 error</title>
      <dc:creator>Kayut</dc:creator>
      <pubDate>Wed, 13 Feb 2019 15:40:43 +0000</pubDate>
      <link>https://forem.com/kayut/react-and-axios---how-to-avoid-404-error-1gon</link>
      <guid>https://forem.com/kayut/react-and-axios---how-to-avoid-404-error-1gon</guid>
      <description>&lt;p&gt;I'm trying to write my very first React application. &lt;br&gt;
In a form with two input fields, the user type the name of a country and a city inside the input fields and submit the form.&lt;br&gt;
city and country variables are then passed to the following component, which should send an API-Request to openweatehrmap API and show the results.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Component } from 'react';
import axios from 'axios';
import Form from './Form/Form';

class Weather extends Component {
  state = {
    country: '',
    city: '',
    currentTemp: '',
    error: undefined,
  }


  getWeather = async (e) =&amp;gt; {
    e.preventDefault();
    const URL = 'http://api.openweathermap.org/data/2.5/weather?q='
    const API_KEY = "8b46d478a9...34a69";
    const country = e.target.elements.country.value;
    const city = e.target.elements.city.value;
    try {
      if (country &amp;amp;&amp;amp; city) {
        const response = await 
axios.get(`${URL}${city},${country}&amp;amp;appid=${API_KEY}&amp;amp;units=metric`);
        const data = await response;
        console.log(data);
        this.setState({
          country: data.data.sys.country,
          city: data.data.name,
          currentTemp: data.data.main.temp,
          error: '',
        });
      } else {
        this.setState({
          country: undefined,
          city: undefined,
          currentTemp: undefined,
          error: 'Please enter a country and a city name'
        })
      }
    } catch (err) {
      this.setState({ error: err })
    }
  }


  render() {
    let showResult;
    if (this.state.error !== undefined &amp;amp;&amp;amp; this.state.country &amp;amp;&amp;amp; this.state.city) {
      showResult =
        &amp;lt;ul&amp;gt;
          &amp;lt;li&amp;gt;Location: {this.state.country} {this.state.city}&amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;Current Temperature: {this.state.currentTemp}° Celsius&amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
    }
    else {
      showResult = &amp;lt;div className="error"&amp;gt;
        {this.state.error}
      &amp;lt;/div&amp;gt;
    }

    return (
      &amp;lt;div&amp;gt;
        &amp;lt;Form onGetWeather={this.getWeather} /&amp;gt;
        {showResult}
      &amp;lt;/div&amp;gt;
    );
  }
}

export default Weather;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If you let one or both input fields empty and submit the form, the UI shows an error.&lt;br&gt;
If you fill in both input fields and the country and the city are related (for example UK and London), the UI shows the temperature and some other info.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;However&lt;/strong&gt;,&lt;br&gt;
If you fill in both input fields with just some random text, or if the country and the city are not related to each other, the App crashes as soon as the form is submitted.&lt;/p&gt;

&lt;p&gt;I think this is because that the generated API-URL isn't valid any more. The console shows the following error:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://thepracticaldev.s3.amazonaws.com/i/zo4rzpflnai896424gq4.png"&gt;https://thepracticaldev.s3.amazonaws.com/i/zo4rzpflnai896424gq4.png&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I spent a whole day, but I couldn't find a way to fix it. How can I avoid the app from crashing. How can I validate the generated API-URL? Or any other hint or solution?&lt;/p&gt;

</description>
      <category>react</category>
      <category>axios</category>
    </item>
    <item>
      <title>Cannot read property 'props' of undefined</title>
      <dc:creator>Kayut</dc:creator>
      <pubDate>Fri, 25 Jan 2019 18:31:08 +0000</pubDate>
      <link>https://forem.com/kayut/cannot-read-property-props-of-undefined-2220</link>
      <guid>https://forem.com/kayut/cannot-read-property-props-of-undefined-2220</guid>
      <description>&lt;p&gt;I get the error: "Cannot read property 'props' of undefined" if I run the following  code. Both files are in the same folder. Can you please explain what am I doing wrong?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;App.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Component } from 'react';
import SeasonDisplay from './SeasonDisplay';

class App extends Component {
  state = {
    lat: null,
    errorMessage: ''
  };

  componentDidMount() {
    window.navigator.geolocation.getCurrentPosition(
      position =&amp;gt; {
        this.setState({
          lat: position.coords.latitude
        });
      },
      err =&amp;gt; {
        console.log(err);
        this.setState({ errorMessage: err.message });
      }
    );
  }

  render() {
    if (this.state.errorMessage &amp;amp;&amp;amp; !this.state.lat) {
      return &amp;lt;div&amp;gt;Error: {this.state.errorMessage}&amp;lt;/div&amp;gt;;
    }
    if (!this.state.errorMessage &amp;amp;&amp;amp; this.state.lat) {
      // return &amp;lt;div&amp;gt;latitude is {this.state.lat}&amp;lt;/div&amp;gt;;
      return &amp;lt;SeasonDisplay lat={this.state.lat} /&amp;gt;;
    }
    return &amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;;
  }
}

export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;SeasonDisplay.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

const SeasonDisplay = props =&amp;gt; {
  return &amp;lt;div&amp;gt;{props.lat}&amp;lt;/div&amp;gt;;
};

export default SeasonDisplay;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>react</category>
      <category>props</category>
      <category>state</category>
    </item>
    <item>
      <title>Class definition in React</title>
      <dc:creator>Kayut</dc:creator>
      <pubDate>Fri, 18 Jan 2019 22:57:08 +0000</pubDate>
      <link>https://forem.com/kayut/class-definition-in-react-4e7n</link>
      <guid>https://forem.com/kayut/class-definition-in-react-4e7n</guid>
      <description>&lt;p&gt;Does a Class component in React need to have a constructor like the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class App extends React.Component {
    constructor() {
        super()
        this.state = {
            count: 0
        }
    }
render() {
  ...
}
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Or now we can define a Class component without using a constructor, like the following example?:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class App extends React.Component {
        this.state = {
            count: 0
        }
render() {
  ...
}
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Which one is correct? &lt;br&gt;
Do we still need to write the constructor for a Class component?&lt;/p&gt;

</description>
      <category>react</category>
      <category>help</category>
    </item>
    <item>
      <title>Using arrow function to define a method</title>
      <dc:creator>Kayut</dc:creator>
      <pubDate>Fri, 18 Jan 2019 16:24:30 +0000</pubDate>
      <link>https://forem.com/kayut/using-arrow-function-to-define-a-method-2em3</link>
      <guid>https://forem.com/kayut/using-arrow-function-to-define-a-method-2em3</guid>
      <description>

&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;I started learning React and right now I'm a bit confused about where to use Arrow-function to define a method and where not to use it.&lt;/p&gt;

&lt;h1&gt;
  
  
  First let's check object literals
&lt;/h1&gt;

&lt;p&gt;This code works:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const person = {
  points: 23,
  score() {
    return this.points++;
  }
};

person.score(); // Works
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But the bellow code doesn't work, because we defined the score() method as an arrow-function:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const person = {
  points: 23,
  score: () =&amp;gt; {     // Arrow function
    return this.points++;
  }
};

person.score(); // Doesn't work
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Take away: Never define methods in an object literal via arrow-function.&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Is the above statement correct?&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What about JavaScript classes?
&lt;/h1&gt;

&lt;p&gt;This code works:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog {
    constructor(name, bread) {
        this.name = name;
        this.bread = bread;
    }

    bark() {
        return `Bark Bark! My name is ${this.name}`;
    }
}
const mini = new Dog('Mini', 'Spitz');
mini.bark();

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And the bellow code, which uses arrow-function syntax to define the bark() method works too:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog {
  constructor(name, bread) {
    this.name = name;
    this.bread = bread;
    this.bark = () =&amp;gt; {     // Arrow function
      return `Bark Bark! My name is ${this.name}`;
    }
  }
}
const mini = new Dog('Mini', 'Spitz');
mini.bark();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Take away: It's fine to define methods in a Class via arrow-function.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is the above statement correct?&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What about React classes (class components)?
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;It is even recommended to use arrow-functions for defining methods inside React classes as a way to create "auto-binding" methods, e.g. methods that could be used by event handlers but that stayed bound to the class.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is the above statement correct?&lt;/strong&gt;&lt;/p&gt;


</description>
      <category>react</category>
      <category>arrowfunction</category>
      <category>method</category>
    </item>
    <item>
      <title>Using arrow functions in object methods</title>
      <dc:creator>Kayut</dc:creator>
      <pubDate>Fri, 18 Jan 2019 12:31:40 +0000</pubDate>
      <link>https://forem.com/kayut/using-arrow-functions-in-object-methods-14pf</link>
      <guid>https://forem.com/kayut/using-arrow-functions-in-object-methods-14pf</guid>
      <description>

&lt;p&gt;Is it possible to use arrow functions to define a method inside a class?&lt;/p&gt;

&lt;p&gt;If it's possible. How can I define the method bark() in the bellow example with arrow function?&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog {
    constructor(name, bread) {
        this.name = name;
        this.bread = bread;
    }

    bark() {
        return `Bark Bark! My name is ${this.name}`;
    }
}
const mini = new Dog('Mini', 'Spitz');
mini.bark();

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I tried this, but it's saying: Uncaught SnytaxError.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bark = () =&amp;gt; {
        return `Bark Bark! My name is ${this.name}`;
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;




</description>
      <category>es6</category>
      <category>arrowfunctions</category>
      <category>method</category>
      <category>react</category>
    </item>
    <item>
      <title> Error: Your render method should have return statement</title>
      <dc:creator>Kayut</dc:creator>
      <pubDate>Thu, 17 Jan 2019 10:58:09 +0000</pubDate>
      <link>https://forem.com/kayut/-error-your-render-method-should-have-return-statement-2hin</link>
      <guid>https://forem.com/kayut/-error-your-render-method-should-have-return-statement-2hin</guid>
      <description>&lt;p&gt;React complains about the following code with the error:  Your render method should have return statement. &lt;/p&gt;

&lt;p&gt;Could you please explain what is exactly wrong with my code inside ToDoItems.js?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ToDoItems.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Component } from 'react';

class Kir extends Component {
  state = {
    todos: [
      {
        id: 1,
        text: 'Take out the trash',
      },
      {
        id: 2,
        text: 'Grocery shopping',
      },
      {
        id: 3,
        text: 'Clean gecko tank',
      }
    ]
  };

  render() {
    const todoItems = this.state.todos.map((todoItem, index) =&amp;gt; {
      return (
        &amp;lt;div key={index}&amp;gt;
          &amp;lt;label&amp;gt;
            &amp;lt;input
              type="checkbox"
              value={todoItem.text}
            /&amp;gt;
            {todoItem.text}
          &amp;lt;/label&amp;gt;
        &amp;lt;/div&amp;gt;
      );
    });
  }
}

export default todoItems;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;ToDo.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Component } from 'react';
import todoItems from './ToDoItems';

class ToDo extends Component {
  render() {
    return (
      &amp;lt;form&amp;gt;
        {todoItems}
      &amp;lt;/form&amp;gt;
    );
  }
}

export default ToDo;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>react</category>
      <category>render</category>
      <category>state</category>
    </item>
    <item>
      <title>How can I loop over this object in React?</title>
      <dc:creator>Kayut</dc:creator>
      <pubDate>Tue, 15 Jan 2019 00:08:32 +0000</pubDate>
      <link>https://forem.com/kayut/how-can-i-loop-over-this-object-in-react-16ob</link>
      <guid>https://forem.com/kayut/how-can-i-loop-over-this-object-in-react-16ob</guid>
      <description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;I'm learning React. In the following component, I import a JS file (data.js), which looks like a JSON file which includes an object.&lt;/p&gt;

&lt;p&gt;Inside the return of the TinTinTile class, I use that object to display all data.&lt;br&gt;
In my example bellow, I can only display the first array in the object. But I need a way to loop over the array jsonResponse.characters.&lt;/p&gt;

&lt;p&gt;Now my question is:&lt;br&gt;
How can I loop over jsonResponse.characters?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Component } from 'react';
import jsonResponse from './data';

console.log(jsonResponse);
// const ArrayLength = jsonResponse.characters.length;
// console.log(ArrayLength);

// jsonResponse.characters.foEach(function(i) {
//   console.log(i);
// });

class TinTinTile extends Component {
  state = {};
  render() {
    return (
      &amp;lt;ul id="container" className="cf"&amp;gt;
        &amp;lt;li className="list-container"&amp;gt;
          &amp;lt;img
            className="image-container"
            src={jsonResponse.characters[0].image_url}
            alt="kir"
          /&amp;gt;
          &amp;lt;div className="text-container"&amp;gt;
            &amp;lt;h4&amp;gt;Name: {jsonResponse.characters[0].name}&amp;lt;/h4&amp;gt;
            &amp;lt;p&amp;gt;Job: {jsonResponse.characters[0].job}&amp;lt;/p&amp;gt;
            &amp;lt;p&amp;gt;Age: {jsonResponse.characters[0].details.age}&amp;lt;/p&amp;gt;

            &amp;lt;button className="btn"&amp;gt;More details ...&amp;lt;/button&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/li&amp;gt;
      &amp;lt;/ul&amp;gt;
    );
  }
}

export default TinTinTile;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>react</category>
      <category>loop</category>
      <category>json</category>
    </item>
  </channel>
</rss>
