Sagar Kothari avatar

Day 4 ReactJS Adventures + Distriator Progress: useState, useEffect, and .env Chaos 😹

sagarkothari88

Published: 30 Jul 2025 β€Ί Updated: 30 Jul 2025Day 4 ReactJS Adventures + Distriator Progress: useState, useEffect, and .env Chaos 😹

Day 4 ReactJS Adventures + Distriator Progress: useState, useEffect, and .env Chaos 😹

πŸ‘‹ Hello Hive Community!

Another day, another ReactJS rollercoaster! 🎒
We've been deep-diving into ReactJS while pushing progress on Project Distriator and CheckInWithXYZ πŸ’ͺ

Let’s rewind βͺ what we’ve covered so far:


🎯 Today's Goals

  1. Learn to integrate .env in React project πŸ”
  2. Implement first useState πŸŽ›οΈ
  3. Try out useEffect (and totally freak out a little) 😡
  4. Share Distriator project updates πŸ“ˆ

πŸ”‘ How to Load .env Values in React (Vite-based)

dot env reference image

If you're using Vite + React like us, it's super simple πŸ‘‡

πŸ—‚οΈ Step 1: Create a .env file
πŸ›‘ Don’t forget to put it inside .gitignore

✨ Prefix all variables with VITE_, like:

VITE_API_KEY=some_key_here

πŸ”“ Access it in your app like this:

import.meta.env.VITE_API_KEY

πŸ”„ How to Use useState

setState example image

useState lets you track and update values inside functional components πŸ“¦

βœ… Step 1: Import it

import { useState } from "react";

βœ… Step 2: Declare a variable

const [businesses, setBusinesses] = useState([]);

In Distriator, we're tracking a list of businesses – so we start with an empty array.

  • businesses: current value
  • setBusinesses: to update the state

Simple & elegant 😎


πŸŒ€ How to Use useEffect (AKA: β€œWhy is my API Calling TWICE?!”)

useEffect Reference image

Okay... so this one had me like πŸ˜΅β€πŸ’«
I initially wrote:

useEffect(() => {
  const fetchedData = async () => {
    // some logic to fetch businesses
  }
  fetchedData();
});

πŸ’£ Result: Infinite reload loop! App was like: "I LIVE TO FETCH!"
I panicked, closed the app, went into full bug-hunting mode πŸ•΅οΈ

🧠 The Fix?

I forgot the dependency array []

useEffect(() => {
  const fetchedData = async () => {
    // some logic to fetch businesses
  }
  fetchedData();
}, []); // Important!

But even then... API was hit twice πŸ˜‘

Two times API calls

Screenshot 2025-07-29 at 5.43.52 AM.png

🎯 Removing StrictMode is a fix...
But let’s be real – not the best one!

controller

Turns out, the smarter way is to use AbortController to clean up async functions.

And yeah... it’s a bit weird. πŸ‘‡

weird

Let’s move on before I rage-quit πŸ™ƒ


🏨 Distriator Project Updates

Big win on Distriator today! πŸŽ‰
We’ve successfully integrated all rooms of Ati Hotel πŸ›οΈ
Deployment is live at: alpha.distriator.com πŸš€

Distriator Changes

☝️ Screenshot above highlights just one file’s worth of changes, but the impact is massive!

Tagging ecoinstant@ecoinstant & starkerz@starkerz so you guys can start playing around on the alpha site!


πŸ™ Thanks for Following Along!

I’ll be back soon with more learnings, bugs, laughs & updates.
Until then β€” keep building, keep shipping! πŸ’»βœ¨

See you in the next post! πŸš€


πŸ“ Final Note


πŸš€ My Contributions to ♦️ Hive Ecosystem

ContributionToHiveEcosystem
Hive Witness NodeHive API Node (in progress)3Speak Video Encoder Node Operator (highest number of nodes)3Speak Mobile App Developer
3Speak Podcast App Developer3Speak Shorts App Developer3Speak Support & Maintenance TeamDistriator Developer
CheckinWithXYZHive InboxHiFindHive Donate App
Contributed to HiveAuth Mobile AppEcency ↔ 3Speak IntegrationEcency ↔ InLeo IntegrationEcency ↔ Actifit Integration
Hive Stats AppVote for Witness AppHiveFlutterKitNew 3Speak App

πŸ™Œ Support Back

❀️ Appreciate my work? Consider supporting threespeak@threespeak & sagarkothari88@sagarkothari88! ❀️

VoteForWitness
sagarkothari88sagarkothari88@sagarkothari88
threespeakthreespeak@threespeak

Leave Day 4 ReactJS Adventures + Distriator Progress: useState, useEffect, and .env Chaos 😹 to:

Written by

App Developer on Hive - Distriator, Check in With XYZ, 3Speak, HiveSuite.app.

Read more #hive posts


Best Posts From Sagar Kothari

We have not curated any of sagarkothari88's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Sagar Kothari