<?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: Prateik Lohani</title>
    <description>The latest articles on Forem by Prateik Lohani (@sanskari_patrick07).</description>
    <link>https://forem.com/sanskari_patrick07</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%2F1582983%2Fa84b37e0-b474-4d52-8c35-25e711d206b1.gif</url>
      <title>Forem: Prateik Lohani</title>
      <link>https://forem.com/sanskari_patrick07</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sanskari_patrick07"/>
    <language>en</language>
    <item>
      <title>Node modules confusion??</title>
      <dc:creator>Prateik Lohani</dc:creator>
      <pubDate>Sun, 27 Oct 2024 06:33:30 +0000</pubDate>
      <link>https://forem.com/sanskari_patrick07/node-modules-confusion-d5g</link>
      <guid>https://forem.com/sanskari_patrick07/node-modules-confusion-d5g</guid>
      <description>&lt;p&gt;I am a beginner to web development and I just created this hardhat project to test a smart contract for a charity donation DApp that has the following folder structure:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1ug5czi4ofmdyayhbti.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1ug5czi4ofmdyayhbti.png" alt="Image description" width="319" height="604"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now how do I add a frontend to this thing? I first initialized it using &lt;code&gt;npm init&lt;/code&gt;, then I added hardhat using &lt;code&gt;npm i hardhat&lt;/code&gt;, intialized the hardhat project using &lt;code&gt;npx hardhat init&lt;/code&gt; and finally did all the testing yada yada...&lt;br&gt;
Until it was done.&lt;/p&gt;

&lt;p&gt;Now how do I add a react frontend to it? I thought about creating another frontend folder here itself in which I'll create all the web pages...&lt;br&gt;
...And it's here where the node modules confusion comes up.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fod8gqm9p5u0zaxexve8u.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fod8gqm9p5u0zaxexve8u.gif" alt="Image description" width="360" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Won't this create 2 node modules folders? One in the main directory, one in the frontend directory? &lt;/p&gt;

&lt;p&gt;Is that good practice? &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>hardhat</category>
      <category>web3</category>
      <category>ethereum</category>
    </item>
    <item>
      <title>Am I wasting time learning Web3?</title>
      <dc:creator>Prateik Lohani</dc:creator>
      <pubDate>Sat, 19 Oct 2024 10:34:05 +0000</pubDate>
      <link>https://forem.com/sanskari_patrick07/am-i-wasting-time-learning-web3-29l7</link>
      <guid>https://forem.com/sanskari_patrick07/am-i-wasting-time-learning-web3-29l7</guid>
      <description>&lt;p&gt;I have just been getting started trying to learn about ethers.js and web3.js. I have learnt a lot of solidity code over the past 2 weeks, but now I am getting skeptical.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;em&gt;&lt;strong&gt;DISCLAIMER&lt;/strong&gt;&lt;/em&gt;&lt;/u&gt;- Before this discussion blows this post out of proportion, let me just put a disclaimer, this is more for a purpose of trying to help me and any other lost soul, trapped helplessly in the the dilemma of learning or not learning Web3- especially considering the ocean-full bucket of content on the internet about whether these technologies are worth a coder's time or not. &lt;/p&gt;

&lt;p&gt;The belligerents in this argument mostly seem to include either outright deniers of blockchain's bright future or optimistic tech geeks that talk like they're straight out of a cypherpunk cult from the 90's. This extreme range has stretched my mind thin on which part of the argument to fall.&lt;/p&gt;

&lt;p&gt;The reason I'm skeptical is because I don't feel like this whole thing is solving a lot of problems. Most of the applications are usually the same as any regular Web2 application with the difference of a smart contract instead of a backend server to manage data and transactions. &lt;/p&gt;

&lt;p&gt;Cryptocurrencies and blockchain as a whole concept seem to be a bit interesting to me as I do like the idea of a decentralized system. However the fact that most of the transactions that occur in it are usually less than 20 per second makes me second guess its future. &lt;/p&gt;

&lt;p&gt;From more of a developer point of view, I don't see Web3 applications solving real life problems so much so as Web2 applications have. Sure privacy is there and it's got a trustless system- great for verifying the transactions in it. &lt;br&gt;
But given that attacks can and still occur is a bit concerning to me. Of course, not every technology is perfect but there is one key thing to consider- does the average user care?&lt;/p&gt;

&lt;p&gt;Does the average user actually give that many sh**s as to whether their data becomes that tiny bit more secure? Don't we all just skip the terms and conditions policies? Don't we all use Instagram, Google or some other shady website every now and then? &lt;/p&gt;

&lt;p&gt;If the problems in Web3 are not being solved MUCH MUCH more efficiently than Web2, why should I as a web developer get into it? If money is the only reason- isn't that technically just a fad then? - in case the demand goes down, so does the job morale, and there goes your daily bread along with any sense of purpose you had with the technology- creating something better.&lt;/p&gt;

&lt;p&gt;I would love to be educated on this but please keep it sane. I am a beginner and not an expert- this is merely something that's been itching my head for the past few weeks and I'd like to get rid of it.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>blockchain</category>
      <category>solidity</category>
      <category>ethereum</category>
    </item>
    <item>
      <title>useEffect() or Event handler?</title>
      <dc:creator>Prateik Lohani</dc:creator>
      <pubDate>Mon, 08 Jul 2024 09:48:54 +0000</pubDate>
      <link>https://forem.com/sanskari_patrick07/useeffect-or-event-handler-1i09</link>
      <guid>https://forem.com/sanskari_patrick07/useeffect-or-event-handler-1i09</guid>
      <description>&lt;p&gt;Hi there!&lt;br&gt;
I just wanted some advice here. Basically I have a To-Do list application that uses a Postgres database and an express backend. I just have one table that stores the name, id, whether completed or not, and a note related to the task in it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh62wbj7gu2lvxnce987l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh62wbj7gu2lvxnce987l.png" alt="An image of my To-Do list application main (and only, lol) page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My doubt is whether I should use a &lt;code&gt;useEffect()&lt;/code&gt; or just plain old event handlers for this.&lt;/p&gt;

&lt;p&gt;This is how I have implemented my functionality:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When a user clicks on the add task button, the event handler- &lt;code&gt;handleAddTask()&lt;/code&gt; fires up -&amp;gt; adds the task to the database -&amp;gt; then fetches the data once again to get the updated data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;NOTE- I am fetching the data again and again since I thought it wouldn't be too bad for an application that is this small (and also because I don't yet know how to do this in a more efficient way🥲).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Similar to the above, when the user deletes a task, a database DELETE request is sent and all the tasks are fetched again to keep the frontend in sync with backend.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Same for editing a task too. Edit it, PUT request goes, and all tasks fetched again.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;code&gt;handleAddTask()&lt;/code&gt; event handler:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 javascript
function handleAddTask(title){
        if (title.trim() === ""){
            alert("You cannot add empty task!");
        }
        else{
            controller.addTask(title)
            .then(() =&amp;gt; controller.fetchData())
            .then((todos) =&amp;gt; {
                console.log("Got your todos!:", todos);
                dispatch({
                    type: "set",
                    todos: todos,
                })
                handleSetTasksRemaining(todos);
            });

            // clearing the task input bar upon adding the task
            setTitle("");
        }
    }


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

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;handleDeleteTask()&lt;/code&gt; event handler:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 javascript
function handleDeleteTask(id){
        controller.deleteTask(id)
        .then(() =&amp;gt; controller.fetchData())
        .then((todos) =&amp;gt; {
            console.log("Got your todos!:", todos);
            flushSync(() =&amp;gt; {
                dispatch({
                    type: "set",
                    todos: todos,
                });
            });
            handleSetTasksRemaining(todos);
        })
    }


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

&lt;/div&gt;

&lt;p&gt;And finally the &lt;code&gt;handleEditTask()&lt;/code&gt; event handler:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 javascript
function handleEditTask(id, title, completed, description, showEditButton){
        setEditInput(showEditButton);

        if(title.trim() === ""){
            alert("You cannot add empty task!");
        } else{
            controller.updateTask(id, title, completed, description === "" ? null : description)
            .then(() =&amp;gt; controller.fetchData())
            .then((todos) =&amp;gt; {
                console.log("Got your todos!:", todos);
                dispatch({
                    type: "set",
                    todos: todos,
                })
                handleSetTasksRemaining(todos);
            })
        }
    }


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

&lt;/div&gt;

&lt;p&gt;I am really confused about what I should do since everyone keeps saying that data fetching should be done in useEffect. But in my case the data should only be added, deleted or edited whenever I click on an appropriate button. &lt;/p&gt;

&lt;p&gt;Is this a bad approach? What is the better approach if any? Please help.&lt;/p&gt;

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