<?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: Tarek Hassan</title>
    <description>The latest articles on DEV Community by Tarek Hassan (@tarekhassan410).</description>
    <link>https://dev.to/tarekhassan410</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%2F97015%2F4f3907c8-6c6a-4881-90f0-4c0e7e8648e0.jpg</url>
      <title>DEV Community: Tarek Hassan</title>
      <link>https://dev.to/tarekhassan410</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tarekhassan410"/>
    <language>en</language>
    <item>
      <title>Making API requests in Laravel</title>
      <dc:creator>Tarek Hassan</dc:creator>
      <pubDate>Sun, 02 May 2021 19:28:21 +0000</pubDate>
      <link>https://dev.to/tarekhassan410/making-api-requests-in-laravel-5301</link>
      <guid>https://dev.to/tarekhassan410/making-api-requests-in-laravel-5301</guid>
      <description>&lt;p&gt;Laravel has a very simple way to make APIs. This article will show you how to make these simple requests.&lt;/p&gt;

&lt;h1&gt;
  
  
  Get requests
&lt;/h1&gt;

&lt;p&gt;To create a basic request, open &lt;code&gt;routes/api.php&lt;/code&gt; and create get request, the syntax looks like that&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::get('/articles', function() {
    return 'Articles';
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will return a page with "Articles".&lt;/p&gt;

&lt;h1&gt;
  
  
  Return JSON
&lt;/h1&gt;

&lt;p&gt;To return a simple JSON response simply use &lt;code&gt;response()-&amp;gt;json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::get('/user', function() {
    return response()-&amp;gt;json([ 'name' =&amp;gt; 'John', ]);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
    </item>
    <item>
      <title>Adding environment variables to React</title>
      <dc:creator>Tarek Hassan</dc:creator>
      <pubDate>Tue, 08 Dec 2020 06:36:56 +0000</pubDate>
      <link>https://dev.to/tarekhassan410/adding-environment-variables-to-react-o18</link>
      <guid>https://dev.to/tarekhassan410/adding-environment-variables-to-react-o18</guid>
      <description>&lt;p&gt;This is a quick guide to adding environment variables to React apps, so let's get to it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 1, Creating .env file
&lt;/h1&gt;

&lt;p&gt;Create a file in your root folder and name it &lt;code&gt;.env&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 2, Adding variables
&lt;/h1&gt;

&lt;p&gt;Inside you .env create variable like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;REACT_APP_SECRET_TOKEN=TOKEN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: variables should start with &lt;code&gt;REACT_APP&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 3, Using variables inside your app
&lt;/h1&gt;

&lt;p&gt;After you added &lt;code&gt;.env&lt;/code&gt; file and variables re-build your app with &lt;code&gt;npm start&lt;/code&gt;. Now you can use your environment variables by simply passing it inside your app &lt;code&gt;{process.env.REACT_APP_SECRET_TOKEN}&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>State management boilerplate with context API </title>
      <dc:creator>Tarek Hassan</dc:creator>
      <pubDate>Wed, 08 Jul 2020 22:50:09 +0000</pubDate>
      <link>https://dev.to/tarekhassan410/state-management-boilerplate-with-context-api-5ba0</link>
      <guid>https://dev.to/tarekhassan410/state-management-boilerplate-with-context-api-5ba0</guid>
      <description>&lt;p&gt;For long time I struggled to manage state with React, but with the release of React Hooks it became so much easier.&lt;/p&gt;

&lt;p&gt;If you are looking for something to grasp the idea and apply it in short time keep on reading.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codesandbox.io/s/hooks-example-8bkmk?file=/src/App.js"&gt;Here is a complete example if you would like to check directly&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up context and context provider
&lt;/h2&gt;

&lt;p&gt;To work with context you first setup context by using &lt;code&gt;createContext()&lt;/code&gt; then you pass props to the provider and use &lt;code&gt;props.chidren&lt;/code&gt; to pass components inside it.&lt;/p&gt;

&lt;p&gt;Here is an example&lt;br&gt;
&lt;/p&gt;

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

export const UsersContext = React.createContext();

export const UsersProvider = props =&amp;gt; {
  const getUsers = async () =&amp;gt; {
    return await fetch("https://jsonplaceholder.typicode.com/users")
      .then(res =&amp;gt; res.json())
      .then(result =&amp;gt; result)
      .catch(error =&amp;gt; console.log("error happened", error));
  };

  return (
    &amp;lt;UsersContext.Provider value={{ getUsers }}&amp;gt;
      {props.children}
    &amp;lt;/UsersContext.Provider&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrapping components inside context
&lt;/h2&gt;

&lt;p&gt;To pass value of context you need to wrap your component inside your context provider, after that you will have access to state in your context from your context. Remember that we passed &lt;code&gt;props.children&lt;/code&gt; inside our context provider.&lt;/p&gt;

&lt;p&gt;Here is an example of how this looks like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import "./styles.css";
import Users from "./Users";
import { UsersProvider } from "../src/Context/UsersContext";

export default function App() {
  return (
    &amp;lt;UsersProvider&amp;gt;
      &amp;lt;div className="App"&amp;gt;
        &amp;lt;h1&amp;gt;Hello Hoooooks&amp;lt;/h1&amp;gt;
        &amp;lt;Users /&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/UsersProvider&amp;gt;
  );
}

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



&lt;h2&gt;
  
  
  Using context and state inside our function
&lt;/h2&gt;

&lt;p&gt;Now after you created context, and you wrapped your component inside provider, it is time to consume it.&lt;/p&gt;

&lt;p&gt;To do this you need &lt;code&gt;useEffect&lt;/code&gt;,&lt;code&gt;useContext&lt;/code&gt; and &lt;code&gt;useState&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;useContext&lt;/code&gt; will pass value and functions to your component so you can have direct access to it. &lt;br&gt;
&lt;code&gt;useEffect&lt;/code&gt; will invoke your &lt;code&gt;getUsers&lt;/code&gt; function to change local state &lt;code&gt;users&lt;/code&gt;&lt;br&gt;
&lt;code&gt;useState&lt;/code&gt; is the new way to use state inside a functional component.&lt;/p&gt;

&lt;p&gt;Here is the complete example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import { UsersContext } from "./Context/UsersContext";

const Users = () =&amp;gt; {
  const [users, setUsers] = React.useState([]);
  const { getUsers } = React.useContext(UsersContext);

  React.useEffect(() =&amp;gt; {
    getUsers().then(result =&amp;gt; {
      setUsers(result);
    });
  }, []);

  return (
    &amp;lt;div&amp;gt;
      {users.map(user =&amp;gt; (
        &amp;lt;div key={user.id}&amp;gt;{user.name}&amp;lt;/div&amp;gt;
      ))}
    &amp;lt;/div&amp;gt;
  );
};

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



&lt;p&gt;This is a summary of what you have done to use context&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You created a file and called it &lt;code&gt;UsersContext&lt;/code&gt; to return an API call to get users from JSONPlaceholder&lt;/li&gt;
&lt;li&gt;You used &lt;code&gt;createContext()&lt;/code&gt; to create context, then You created context provider and passed value object inside with our functions.&lt;/li&gt;
&lt;li&gt;In &lt;code&gt;App.js&lt;/code&gt; you passed provider to access context state and functions.&lt;/li&gt;
&lt;li&gt;In &lt;code&gt;Users.js&lt;/code&gt; you called context with &lt;code&gt;useContext&lt;/code&gt; hook and passed users inside your component.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Creating Chrome extension in under five minutes</title>
      <dc:creator>Tarek Hassan</dc:creator>
      <pubDate>Wed, 01 Jul 2020 17:37:31 +0000</pubDate>
      <link>https://dev.to/tarekhassan410/creating-chrome-extension-in-under-five-minutes-2cg9</link>
      <guid>https://dev.to/tarekhassan410/creating-chrome-extension-in-under-five-minutes-2cg9</guid>
      <description>&lt;p&gt;Developing an extension for chrome is very easy and doable with just HTML, CSS and JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are we building
&lt;/h2&gt;

&lt;p&gt;We are building simple extension that reads an API from Breaking Bad quotes and shows it, that is it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1
&lt;/h2&gt;

&lt;p&gt;We need to create few files to have a chrome extension &lt;code&gt;index.html&lt;/code&gt;, &lt;code&gt;manifest.json&lt;/code&gt; ,&lt;code&gt;script.js&lt;/code&gt; and a png file for your icon. You can add style.css file and link it but I am keeping this as simple as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 - working with manifest.json
&lt;/h2&gt;

&lt;p&gt;This is a JSON file that contains data about your extension. &lt;br&gt;
Most of its attributes are self explanatory. Here is a full example of our extension &lt;code&gt;manifest.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "manifest_version": 2,
  "name": "Breaking bad",
  "description": "The breaking bad quote extension",
  "version": "1.0",
  "browser_action": {
    "default_icon": "bb.png",
    "default_popup": "index.html"
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Please note that manifest_version, name and version are required. &lt;br&gt;
Most important part here is &lt;code&gt;browser_action&lt;/code&gt;. This is where you tell chrome where to find file to open and icon to have in chrome.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3 - Markup
&lt;/h2&gt;

&lt;p&gt;This markup is going to to have a header and a section to have our quote after API calling is done&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Breaking bad&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;main style="text-align: center;" class="pt-20"&amp;gt;
      &amp;lt;h1 class="text-center text-4xl font-bold leading-10 tracking-wide"&amp;gt;
        Breaking bad quotes
      &amp;lt;/h1&amp;gt;
      &amp;lt;section id="quote-section"&amp;gt;&amp;lt;/section&amp;gt;
    &amp;lt;/main&amp;gt;
    &amp;lt;script src="script.js"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4 - The JS part
&lt;/h2&gt;

&lt;p&gt;In our index.html we have imported &lt;code&gt;script.js&lt;/code&gt; file. This file is going to call &lt;code&gt;https://breaking-bad-quotes.herokuapp.com/v1/quotes&lt;/code&gt; and get a random Breaking Bad quote. &lt;/p&gt;

&lt;p&gt;Here is the script for our extension&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var quoteSection = document.getElementById('quote-section');

fetch('https://breaking-bad-quotes.herokuapp.com/v1/quotes')
  .then((res) =&amp;gt; res.json())
  .then((res) =&amp;gt; {
    console.log(res);
    quoteSection.innerHTML = '&amp;lt;div&amp;gt;' + res[0].quote + '&amp;lt;/div&amp;gt;' + '&amp;lt;h4&amp;gt;' + res[0].author + '&amp;lt;/h4&amp;gt;';
  });
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5 - Uploading extension
&lt;/h2&gt;

&lt;p&gt;This is s simple drag and drop step. But before make sure you have enabled developer mode in your browser. Then head to &lt;code&gt;chrome://extensions/&lt;/code&gt; and drag the folder where all files in and drop inside extensions tab.&lt;/p&gt;

&lt;p&gt;That is it. The full code is found &lt;a href="https://github.com/tarekhassan410/BreakingBadExtension"&gt;in this repo.&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is your experience with mentorship? </title>
      <dc:creator>Tarek Hassan</dc:creator>
      <pubDate>Sat, 16 Nov 2019 00:17:04 +0000</pubDate>
      <link>https://dev.to/tarekhassan410/what-is-your-experience-with-mentorship-2i8k</link>
      <guid>https://dev.to/tarekhassan410/what-is-your-experience-with-mentorship-2i8k</guid>
      <description>&lt;p&gt;If you have worked with a mentor, how was that? Did it help? &lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>How to develop a digital wallet app?</title>
      <dc:creator>Tarek Hassan</dc:creator>
      <pubDate>Fri, 20 Sep 2019 13:21:16 +0000</pubDate>
      <link>https://dev.to/tarekhassan410/how-to-develop-a-digital-wallet-app-2k73</link>
      <guid>https://dev.to/tarekhassan410/how-to-develop-a-digital-wallet-app-2k73</guid>
      <description>&lt;p&gt;Hello Devs, I want to practice by building small digital wallet app like Paytm in India, how can I do that? &lt;br&gt;
To build it, should I connect every user to a bank account? Or I should manage payments through my database? How this works?&lt;/p&gt;

</description>
      <category>question</category>
    </item>
    <item>
      <title>Get to know CSS and Flexbox properly before getting into JS (and Bootstrap)</title>
      <dc:creator>Tarek Hassan</dc:creator>
      <pubDate>Sun, 21 Jul 2019 14:38:17 +0000</pubDate>
      <link>https://dev.to/tarekhassan410/get-to-know-css-and-flexbox-properly-before-getting-into-js-3654</link>
      <guid>https://dev.to/tarekhassan410/get-to-know-css-and-flexbox-properly-before-getting-into-js-3654</guid>
      <description>&lt;p&gt;I recently came to realize that CSS is very important before diving into JS. I have worked with different frameworks like Bootstrap and Vuetify. But recently I decided to take one step back and take a course on CSS only.&lt;/p&gt;

&lt;p&gt;I had a project which I struggled for days to create styling and all CSS stuff. I used Bootstrap for it but I had issues here and there that I couldn't fix. After finishing 60% of this course I re-made this project design with help of Flexbox and pure CSS, this time it took me only few hours to achieve what I achieved in days before. &lt;/p&gt;

&lt;p&gt;For example, I used to use px most of the time and I didn't know what is em and rem. I also didn't understand well what is position. &lt;/p&gt;

&lt;p&gt;So as some advise juniors to start with Vanilla JS before frameworks, I think the same applies to CSS and frameworks. Understand CSS well before getting into Frameworks. &lt;/p&gt;

&lt;p&gt;Happy coding. &lt;/p&gt;

</description>
      <category>opinion</category>
    </item>
    <item>
      <title>How do you make balance between working and studying?</title>
      <dc:creator>Tarek Hassan</dc:creator>
      <pubDate>Tue, 02 Jul 2019 08:57:02 +0000</pubDate>
      <link>https://dev.to/tarekhassan410/how-do-you-make-balance-between-working-and-studying-3f05</link>
      <guid>https://dev.to/tarekhassan410/how-do-you-make-balance-between-working-and-studying-3f05</guid>
      <description>&lt;p&gt;I am wondering about this as I am very stressed nowadays because of it. I have 9-5 as Frontend developer but I would like to really improve my skills. I subscribed to Vue mastery but actually finding time to study is hard, especially that I want to improve in both Vue and JavaScript besides wanting to learn other skills like Graphql and Firebase. &lt;/p&gt;

&lt;p&gt;So much things to learn but the day job simply eats your day and sometimes I have to work after 5 to finish something. &lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>React js Contentful starting</title>
      <dc:creator>Tarek Hassan</dc:creator>
      <pubDate>Tue, 13 Nov 2018 08:43:37 +0000</pubDate>
      <link>https://dev.to/tarekhassan410/react-js-contentful-starting-32h3</link>
      <guid>https://dev.to/tarekhassan410/react-js-contentful-starting-32h3</guid>
      <description>&lt;p&gt;Contentful is headless CMS that you can use for building your content from its ready back-end and fetch your content with RESTFUL-API. &lt;/p&gt;

&lt;p&gt;In this tutorial I am going to share with you how to start a simple project on Contentful and React js. &lt;/p&gt;

&lt;p&gt;This tutorial assumes that you are already familiar with React and creating React project.&lt;/p&gt;

&lt;p&gt;I will explain creating and connecting to Contentful in steps.&lt;/p&gt;

&lt;p&gt;But first you need to have a Contentful account, simply go to &lt;a href="https://www.contentful.com/sign-up/" rel="noopener noreferrer"&gt;https://www.contentful.com/sign-up/&lt;/a&gt; and sign up then sign in. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;4 simple steps for creating content on Contentful&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First step: After you sign in go to the navbar to the left and choose to create a new space. This is where your data will be saved. For this tutorial I named the space 'Blog'.&lt;/p&gt;

&lt;p&gt;Second step: is to make content type. If you are adding a structure for 'articles' make you content type as 'article'. When add content in next step you will find 'add article' button to add content. &lt;/p&gt;

&lt;p&gt;Let's continue making the data model.&lt;/p&gt;

&lt;p&gt;After you created your content type you can find 'add field'. &lt;/p&gt;

&lt;p&gt;Add field -&amp;gt; text -&amp;gt; short text -&amp;gt; make the title 'post title'&lt;br&gt;
Add field -&amp;gt; text -&amp;gt; long text -&amp;gt; make the title 'post content'&lt;br&gt;
Add field -&amp;gt; text -&amp;gt; short text -&amp;gt; make the title 'post author'&lt;/p&gt;

&lt;p&gt;If you are following you get the idea. You can add more fields of you would like to. &lt;/p&gt;

&lt;p&gt;On the top NavBar click 'content'. Save and go to content.&lt;/p&gt;

&lt;p&gt;Third step: Adding content should be so simple. Just click 'add article' in case you chose your content type as 'article'. Then you are adding content as you would do on WordPress. You can use Lorem ipsum generators like &lt;a href="http://lorem-ipsum.perbang.dk/" rel="noopener noreferrer"&gt;http://lorem-ipsum.perbang.dk/&lt;/a&gt; to generate content for testing.&lt;/p&gt;

&lt;p&gt;Last step: is fetching content you created. &lt;/p&gt;

&lt;p&gt;You need to get your 'access token' and 'space ID' from Space setting -&amp;gt; API keys&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 { render } from "react-dom";
import { createClient } from "contentful";


var client = createClient({
  space: "YOUR_SPACE_ID",
  accessToken:
    "YOUR_ACCESS_TOKEN"
});

class App extends Component {
  constructor() {
    super();
    this.state = {
      article: []
    };
  }

  componentDidMount() {
    client.getEntries().then(({ items }) =&amp;gt; {
      this.setState({ articles: items });
    });
  }

  render() {
    return (
      &amp;lt;div&amp;gt;
        Content goes here
      &amp;lt;/div&amp;gt;
    );
  }
}

render(&amp;lt;App /&amp;gt;, document.getElementById("root"));

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

&lt;/div&gt;



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