<?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: DennisVN</title>
    <description>The latest articles on DEV Community by DennisVN (@dennisvn).</description>
    <link>https://dev.to/dennisvn</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%2F693218%2F676834c3-a008-4eb0-b681-02ddc671f92e.jpeg</url>
      <title>DEV Community: DennisVN</title>
      <link>https://dev.to/dennisvn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dennisvn"/>
    <language>en</language>
    <item>
      <title>PostgreSQL terminal: a CRUD beginner guide (Windows 10).</title>
      <dc:creator>DennisVN</dc:creator>
      <pubDate>Sat, 27 Nov 2021 16:34:43 +0000</pubDate>
      <link>https://dev.to/dennisvn/postgresql-terminal-a-crud-beginner-guide-windows-10-55e5</link>
      <guid>https://dev.to/dennisvn/postgresql-terminal-a-crud-beginner-guide-windows-10-55e5</guid>
      <description>&lt;p&gt;For all my beginners out there, i began using PostgreSQL this morning. This article will help you with initiating and editing in the SQL shell. This article will &lt;strong&gt;not&lt;/strong&gt; cover installation, and won't cover the GUI. This means that i expect you to have completed installation, and allready set a password throught the GUI. &lt;br&gt;During my webdev bootcamp we learned working with MySQL and MAMP, but i find them very different, so i hope this article helps you to save some time at researching. Let's get started ! &lt;/p&gt;

&lt;h1&gt; Getting inside SQL through the terminal &lt;/h1&gt;

&lt;p&gt;i still find working through terminal quite tedious as i always get classic errors like "wrong host", "wrong password", "access denied" and all them classic shenanigans. It's pretty straightforward in this case :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Start &amp;gt; PostgreSQL 14 &amp;gt; SQL shell (psql)&lt;/code&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;the terminal opens and this is the one line you see :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Server [localhost]:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here is where my confusion started, but basically, all you have to do is &lt;strong&gt;leave it blank &amp;amp; press enter&lt;/strong&gt;. Same for the following fields that pop up :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Server [localhost]: (leave empty, press the ENTER key)
Database [postgres]: (leave empty,press the ENTER key)
Port [5432]: (leave empty,press the ENTER key)
Username [postgres]: (leave empty,press the ENTER key)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now hold on, because the next one is PASSWORD. Here you have to insert the password that you set with the installation. Once you passed that, you are in ! well done. &lt;br&gt;&lt;/p&gt;

&lt;p&gt;Let's go over the commands to get you started. Here's your first one : &lt;/p&gt;

&lt;p&gt;&lt;code&gt;help&lt;/code&gt;&lt;br&gt;
this will give you :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

--&amp;gt; press q to quit list 


\l to see an overview of all databases 
(offcourse it is empty for now)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So let us create a new database called 'test' : &lt;br&gt;&lt;br&gt;
The command for this is :&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE DATABASE test;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Please not the importance of putting the semicolon at the end. Later on we will see that the terminal only executes after a semicolon. If you press enter without ending with a semicolon, the terminal expects you to continue typing.&lt;br&gt;
Let's check if worked with : &lt;br&gt;&lt;br&gt;
&lt;code&gt;\l&lt;/code&gt;&lt;br&gt;
to check our list again, you will see it has been added ! &lt;br&gt;&lt;br&gt;
&lt;strong&gt;Congratulations, we just opened the terminal, did our first basic commands, and we allready created a brand new list without touching the GUI.&lt;/strong&gt; &lt;br&gt;&lt;/p&gt;

&lt;h2&gt; But how to check out a specific database ?&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;close your terminal, and let's start from scratch.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When you open the Shell again (pro-tip: put a shortcut on your desktop to save time) and repeat previous steps. The only difference here will be that we going to tell postgres that we want to go to our newly created 'test' database. So don't go to fast, database is the second prompt you'll get ;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Server [localhost]:
Database [postgres]:test 
Port [5432]:
Username [postgres]:
Password for user postgres:(enter the one you created).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you will get a warning message, just ignore it.&lt;br&gt;
Next up use the following command to see what's in our 'test' database : &lt;br&gt;
&lt;code&gt;\d&lt;/code&gt;&lt;br&gt;
If you are good at guessing, you can allready tell it's going to be empy. If not, this is what will appear in the terminal :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Did not find any relations.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this is where the fun begins ! &lt;/p&gt;

&lt;h2&gt; Manipulating our database through the terminal &lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;In this part we go over basic CRUD commands to add, read, update and delete the information in our 'test' database.&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;ADD &amp;amp; READ NEW TABLE :&lt;/strong&gt;&lt;br&gt;
In our 'test' db, we will create a &lt;code&gt;table&lt;/code&gt; called &lt;code&gt;person&lt;/code&gt;. That person wil have following properties :  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;id ( number (int), a primary key, autoincrementing.)&lt;/li&gt;
&lt;li&gt;name ( letters (characters), 100 max )&lt;/li&gt;
&lt;li&gt;country ( letters (characters), 50 max )&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will have to define the type of data the properties get. Our id wil be an integer for example, but with an &lt;code&gt;autoincrement&lt;/code&gt; function. This so our &lt;code&gt;id&lt;/code&gt; will be automaticaly  sequenced by postgres. Let me show you what i mean. This is how we do it :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE person (
id BIGSERIAL NOT NULL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
country VARCHAR(50) NOT NULL );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;! Note how there is no semicolon until the fourth line.&lt;/strong&gt; &lt;br&gt;
We can press &lt;code&gt;ENTER&lt;/code&gt; after &lt;br&gt;
&lt;code&gt;CREATE TABLE person (&lt;/code&gt;&lt;br&gt;
and start the new line. Once you're finished, put a semicolon &lt;code&gt;;&lt;/code&gt; and press enter, only then terminal will execute those commands.&lt;br&gt;
The terminal then confirms your creation and tells you:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now check again to see what's in our 'test' with :&lt;br&gt;
&lt;code&gt;\d&lt;/code&gt;&lt;br&gt;
and terminal will show you :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test=# \d
              List of relations
 Schema |     Name      |   Type   |  Owner
--------+---------------+----------+----------
 public | person        | table    | postgres
 public | person_id_seq | sequence | postgres
(2 rows)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Here you'll notice how the second row has&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public | person_id_seq | sequence | postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This is the built-in sequencer from postgres, that'll make sure to check and auto increment our &lt;code&gt;id&lt;/code&gt; property 24/7. Pretty awesome right ?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We have just checked our database, now let's check out our table with the command: &lt;br&gt;
&lt;code&gt;\dt&lt;/code&gt;&lt;br&gt;
Then terminal will show you :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test=# \dt
         List of relations
 Schema |  Name  | Type  |  Owner
--------+--------+-------+----------
 public | person | table | postgres
(1 row)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;ADD NEW INFORMATION IN OUR TABLES  :&lt;/strong&gt;&lt;br&gt;
Now that we have created our new &lt;code&gt;person&lt;/code&gt; table, let's populate it. AKA let's &lt;strong&gt;INSERT&lt;/strong&gt; the &lt;strong&gt;VALUE&lt;/strong&gt;s for a new person. You can do this with : &lt;br&gt;
&lt;code&gt;INSERT INTO person (name, country) VALUES ('Jean-Baptiste', 'BEL');&lt;/code&gt;&lt;br&gt;&lt;br&gt;
press &lt;code&gt;ENTER&lt;/code&gt; and you'll see :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test=# INSERT INTO person (name, country) VALUES ('Jean-Baptiste', 'BEL');
INSERT 0 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;let's add two more : &lt;br&gt;
&lt;code&gt;INSERT INTO person (name, country) VALUES ('Jev', 'US');&lt;/code&gt;&lt;br&gt;
&lt;code&gt;INSERT INTO person (name, country) VALUES ('Rudy', 'UK');&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then it should look 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;test=# INSERT INTO person (name, country) VALUES ('Jev', 'US');
INSERT 0 1
test=# INSERT INTO person (name, country) VALUES ('Rudy', 'UK');
INSERT 0 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A way to see everything from person is : &lt;br&gt;
&lt;code&gt;SELECT * FROM person;&lt;/code&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;*&lt;/code&gt; means &lt;code&gt;EVERYTHING / ALL&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test=# SELECT * FROM person;
 id |      name       | country
----+-----------------+---------
  1 | Jean-Baptiste   | BEL
  2 | jev             | US
  3 | Rudy            | UK
(3 rows)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;extra: let's say you want the count of all your persons : &lt;br&gt;
&lt;code&gt;SELECT COUNT(id) FROM person;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test=# SELECT COUNT(id) FROM person;
 count
-------
     3
(1 row)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Well done, we've just added three people in our person database ! We were also able to read it, and to count how many people are in our database. If this were thousands of people, this was very welcome.&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;strong&gt;UPDATE THE INFORMATION IN OUR TABLES  :&lt;/strong&gt;&lt;br&gt;
What if we have to change a name that we have in the database ? No need to delete and re-enter, you can use the following command : &lt;br&gt;
&lt;code&gt;UPDATE person SET name = 'Tapis-Plain' WHERE id  = 1;&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;for my OG readers, my French is still lame ...
We select here based on ID with the id of '1', in our example this is Jean-Baptiste. Let's check again.
The console will return
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;UPDATE 1&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now let's chek again with &lt;br&gt;
&lt;code&gt;SELECT * FROM person;&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;test=# SELECT * FROM person;
 id |      name       | country
----+-----------------+---------
  2 | jev             | US
  3 | Rudy            | UK
  1 | Tapis-Plain     | BEL
(3 rows)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Very cool and good but ... 'Tapis-Plain' is a fabric and not a person's name. That's just silly ! So let's delete it, OK ? Last step incoming, you're almost there ! &lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DELETE INFORMATION IN OUR TABLES  :&lt;/strong&gt;&lt;br&gt;
Pretty straightforward. With the previous knowledge, we apply it to the &lt;code&gt;DELETE&lt;/code&gt; command and you're good to go : &lt;br&gt;
&lt;code&gt;DELETE FROM person WHERE id = 1;&lt;/code&gt;&lt;br&gt;
&lt;code&gt;SELECT * FROM person;&lt;/code&gt;&lt;br&gt;
The result :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test=# SELECT * FROM person;
 id |      name       | country
----+-----------------+---------
  2 | jev             | US
  3 | Rudy            | UK
(2 rows)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;YOU DID IT ! Create, Read, Update and Delete (aka CRUD) in the Postgres SQL terminal.&lt;/strong&gt;&lt;br&gt;
Well done ! You just applied all needed techniques for a real world crud database. Before we end this rather long read, i'll leave you with a last command, handy when you want a more detailed overview of your database. This is called the &lt;code&gt;expanded view&lt;/code&gt; : &lt;br&gt;
&lt;code&gt;\x&lt;/code&gt;&lt;br&gt;
Terminal will show you :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test=# \x
Expanded display is on.
test=# SELECT * FROM person;
-[ RECORD 1 ]------------
id      | 2
name    | Beaucoupdargent
country | BEL
-[ RECORD 2 ]------------
id      | 3
name    | Magere
country | BEL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To leave this view press &lt;br&gt;
&lt;code&gt;q&lt;/code&gt; or &lt;code&gt;\x once more&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt; Thanks for peepin', i sincerely hope this was useful for my beginners out there. See you in the next article ! &lt;/h2&gt;

</description>
      <category>webdev</category>
      <category>crud</category>
      <category>postgres</category>
      <category>database</category>
    </item>
    <item>
      <title>React TSX: passing props with useContext (beginner guide) Part 1/2</title>
      <dc:creator>DennisVN</dc:creator>
      <pubDate>Wed, 10 Nov 2021 15:53:45 +0000</pubDate>
      <link>https://dev.to/dennisvn/react-tsx-passing-props-with-usecontext-beginner-guide-part-12-53g1</link>
      <guid>https://dev.to/dennisvn/react-tsx-passing-props-with-usecontext-beginner-guide-part-12-53g1</guid>
      <description>&lt;p&gt;I'm 7 months into coding now, simply love React so I dedicated to write my tech article about it.
You can consider a 'classic' way of passing data, is passing data through a JSON list or Database.
This often causes having to re-deconstruct the State in each new child component. 
To avoid this you can use the useContext hook in React, and pass it's props through a ContextProvider very easily.&lt;/p&gt;

&lt;p&gt;This article will show you how to pass data from one central useContext that provides it's props to all components.&lt;br&gt;
To go even further, we will edit the data and pass it to our screen and localStorage in part 2 of this beginner guide ! &lt;br&gt;
And yes, i mean ALL children. Let's start with context for now ! &lt;/p&gt;


&lt;center&gt;&lt;h1&gt;Action plan &lt;/h1&gt;&lt;/center&gt;

&lt;h2&gt;In this example we are creating a restaurant's menu that displays a daily 3 course meal for Monday-Saturday.
Before i spill the tea, let's start with the structure and action plan.&lt;/h2&gt;

&lt;p&gt;Please note that i expect you to have a basic understanding in React x TSX, and how components &amp;amp; React-Router-Dom works. &lt;br&gt;
This however easily translates in JS for those who are not familiar in Typescript !&lt;br&gt;
&lt;/p&gt;
&lt;center&gt;
&lt;h1&gt;Let's get started !&lt;/h1&gt;
&lt;br&gt;
In this project our initial Routing is structured as followed : &lt;/center&gt;
&lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App () {
&amp;lt;&amp;gt;
&amp;lt;div className="App&amp;gt;
    &amp;lt;Router&amp;gt;
    &amp;lt;Navbar&amp;gt;
    &amp;lt;Switch&amp;gt;
        &amp;lt;Route path="/menus" component={Menus}&amp;gt;&amp;lt;/Route&amp;gt;
    &amp;lt;Switch&amp;gt;
    &amp;lt;Navbar&amp;gt;
    &amp;lt;Router&amp;gt;
    &amp;lt;Footer&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Note that there are other components in the OG project, but these are irrelevant in our case. &lt;br&gt;&lt;br&gt;
Important before you proceed is making an action plan, by dedicating the correct Parent &amp;amp; Children. For our menu this will be as followed : &lt;br&gt;&lt;/p&gt;


&lt;center&gt;&lt;h1&gt;Component tree in App.tsx :&lt;/h1&gt;&lt;/center&gt;
&lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Menus&amp;gt; = Parent Component 
-(redirected from App with Route to component={Menus}.)
    &amp;lt;MenuCard&amp;gt; = Child component 
-(This will be the "card" for the COMPLETE week. 
        &amp;lt;AddForm&amp;gt; = Child Component 
-( We need this later in a modal to edit the data )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Where is your useContext i hear you think ? this is a global component so it has it's own place. &lt;br&gt;&lt;br&gt;
We will need a Provider to "inject" other components with it's props.&lt;br&gt;
This means once you pass the props in a component, this comp will be "Provided" with the needed data !&lt;br&gt;
Here we call it MenuContextProvider because obviously we are working on a Menu.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;Step 1 : Setting up our useContext &lt;/h2&gt;

&lt;p&gt;First off, we obviously need to import &amp;amp; declare the context hook from React in this component :&lt;br&gt;
-import { createContext } from "react";&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;Step 2 : Declaring data &amp;amp; objects inside context &lt;/h2&gt;

&lt;p&gt;To know how to pass the props we need to create our data and destructure it first.&lt;br&gt;
We only need to do this once, here in this component. &lt;br&gt;
Create a new State, which we will use as an Array of Objects. &lt;br&gt;
Let's call this menus in our example ! This is how it looks :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const [menus, setMenus] = useState([
        { id: uuidv4(), day:"Monday", nameStarter: "Pôtage du jour", priceStarter: 4.20, nameMain: "Pomme d'amour", priceMain: 6.90 , nameDessert: "Salade du fruits", priceDessert: 4.20, totalPrice: 13.50, },
        { id: uuidv4(), day: "Tuesday", nameStarter: "Croquette crevette", priceStarter: 4.20 ,nameMain: "Moules Frites", priceMain: 6.90 , nameDessert: "Mousse au chocolat", priceDessert: 4.20, totalPrice: 13.50, },
        { id: uuidv4(), day: "Wednesday", nameStarter: "Croquette fromage", priceStarter: 4.20 , nameMain: "Pain Saucisse", priceMain: 6.90 , nameDessert: "Mousse au fraise", priceDessert: 4.20, totalPrice: 13.50, }, 
        { id: uuidv4(), day: "Thursday", nameStarter: "Croquette duo", priceStarter: 4.20 , nameMain: "Pain Fromage", priceMain: 6.90 , nameDessert: "Mousse au Camembert", priceDessert: 4.20, totalPrice: 13.50, },
        { id: uuidv4(), day: "Friday", nameStarter: "Cocktail of crevettes", priceStarter: 4.20 , nameMain: "Panette poison", priceMain: 6.90 , nameDessert: "Mousse au Brie", priceDessert: 4.20, totalPrice: 13.50, },
        { id: uuidv4(), day: "Saturday", nameStarter: "Carpaccio", priceStarter: 4.20 , nameMain: "Pain Jambon", priceMain: 6.90 , nameDessert: "Tiramisu", priceDessert: 4.20, totalPrice: 13.50, }
    ])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are some take aways here : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;my French is lame &lt;/li&gt;
&lt;li&gt;for id I used uuidv4(). You can go for a class with name Id, but often you will get an error as unique ID's are required for each item. uuidv4() creates random strings as an ID, which makes it easy to imply those unique ID's ! Don't forget to import this on top of our context component !
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { v4 as uuidv4 } from 'uuid';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h2&gt;Step 3 : Setting up MenuContextProvider&lt;/h2&gt;

&lt;p&gt;We already know why we need a provider.&lt;br&gt;
But how does it look, and how are we going to use and pass it ? &lt;/p&gt;

&lt;p&gt;First off we need to create a new context. React does this with createContext. Again make sure you imported useContext on top of the component.&lt;br&gt;&lt;br&gt;
Since we are using typescript , we need to declare some extra types.&lt;/p&gt;

&lt;p&gt;It took me a while to figure this out, but this is how it looks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const MenuContext = createContext&amp;lt; any | undefined&amp;gt;(undefined);

- const MenuContextProvider = (props) =&amp;gt; {
    return(
        &amp;lt;MenuContext.Provider&amp;gt;
            {props.children}
        &amp;lt;/MenuContext.Provider&amp;gt;
    )
}
export {MenuContextProvider}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note how we export the MenuContext as an Object aka {MenuContext} ! Important that we import this likewise in the other components.&lt;br&gt;&lt;br&gt;
Note how  is different from  ! &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&amp;lt; MenuContext.Provider &amp;gt; is only needed in our routing which needs the .Provider to send the props. &lt;/li&gt;
&lt;li&gt;&amp;lt; MenuContextProvider &amp;gt; works as the function component and will be imported in other components to process the State. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Step 4 : Context &amp;amp; React-Router-DOM&lt;/h2&gt;

&lt;p&gt;This step will show you how to inject your routing and links with the props, and Provide the pages with the data.&lt;br&gt;
In fact this is very easy; We place the .Provider around the Router. This means all components become a Child from the .Provider. &lt;br&gt;
Crazy right ? This is how it looks in our App.tsx;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import Navbar from '../src/components/Navbar';
import Footer from './components/Footer';
import Menus from './components/Menus';
import {MenuContextProvider} from './contexts/MenuContext';

    function App () {
    &amp;lt;MenuContextProvider&amp;gt;
    &amp;lt;div className="App&amp;gt;
        &amp;lt;Router&amp;gt;
            &amp;lt;Navbar&amp;gt;
                &amp;lt;Switch&amp;gt;
                    &amp;lt;Route path="/menus" component={Menus}&amp;gt;&amp;lt;/Route&amp;gt;
                &amp;lt;Switch&amp;gt;
            &amp;lt;Navbar&amp;gt;
        &amp;lt;Router&amp;gt;
        &amp;lt;Footer&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;/MenuContextProvider&amp;gt;
    }
    export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't forget to import the Provider on top of the component, and as mentioned, as an Object !&lt;br&gt;
Well done, you injected the {props.children} of the context in all Child components !&lt;/p&gt;

&lt;p&gt;Let sip our drink, and overview our MenuContextProvider component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createContext, useEffect, useState } from "react";
import { v4 as uuidv4 } from 'uuid';

export const MenuContext = createContext&amp;lt; any | undefined&amp;gt;(undefined);

const MenuContextProvider = (props) =&amp;gt; {

    const [menus, setMenus] = useState([
        { id: uuidv4(), day:"Monday", nameStarter: "Pôtage du jour", priceStarter: 4.20, nameMain: "Pomme d'amour", priceMain: 6.90 , nameDessert: "Salade du fruits", priceDessert: 4.20, totalPrice: 13.50, },
        { id: uuidv4(), day: "Tuesday", nameStarter: "Croquette crevette", priceStarter: 4.20 ,nameMain: "Moules Frites", priceMain: 6.90 , nameDessert: "Mousse au chocolat", priceDessert: 4.20, totalPrice: 13.50, },
        { id: uuidv4(), day: "Wednesday", nameStarter: "Croquette fromage", priceStarter: 4.20 , nameMain: "Pain Saucisse", priceMain: 6.90 , nameDessert: "Mousse au fraise", priceDessert: 4.20, totalPrice: 13.50, }, 
        { id: uuidv4(), day: "Thursday", nameStarter: "Croquette duo", priceStarter: 4.20 , nameMain: "Pain Fromage", priceMain: 6.90 , nameDessert: "Mousse au Camembert", priceDessert: 4.20, totalPrice: 13.50, },
        { id: uuidv4(), day: "Friday", nameStarter: "Cocktail of crevettes", priceStarter: 4.20 , nameMain: "Panette poison", priceMain: 6.90 , nameDessert: "Mousse au Brie", priceDessert: 4.20, totalPrice: 13.50, },
        { id: uuidv4(), day: "Saturday", nameStarter: "Carpaccio", priceStarter: 4.20 , nameMain: "Pain Jambon", priceMain: 6.90 , nameDessert: "Tiramisu", priceDessert: 4.20, totalPrice: 13.50, }
    ])


    return(
        &amp;lt;MenuContext.Provider value={{menus}}&amp;gt;
            {props.children}
        &amp;lt;/MenuContext.Provider&amp;gt;
    )
}
export {MenuContextProvider};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see the value for the .Provider allready has the menus props passed. &lt;br&gt;
This is the object that we created in our hook [menus, setMenus]. We don't use setMenus for now, so if you like you can remove it.&lt;/p&gt;

&lt;p&gt;And there you go ! you just set up the useContext of an Array of Objecs, and dissected the props. From here you can easily deconstruct these props by passing them as a value for your components ! in part 2/2 i will show you how easy it is to get the wanted data, and also how to save them in localStorage. We go as far as creating a modal that pops up &amp;amp; where you can update the menu. Part one is allready quite the read, so i let you digest this one first ;) ! &lt;/p&gt;



&lt;center&gt;&lt;h1&gt; Thanks for peepin' &amp;amp; see you in part 2 ! &lt;/h1&gt;&lt;/center&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>typescript</category>
      <category>tsx</category>
    </item>
  </channel>
</rss>
