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:
- π Day One: Fresh React app + AIOHA integration!
- π§ Day Two: Routing drama & rebellious NavBar π€
- π οΈ Day Three: Fixed Layouts, Routing & AIOHA π₯
- Today is Day Four π
π― Today's Goals
- Learn to integrate
.envin React project π - Implement first
useStateποΈ - Try out
useEffect(and totally freak out a little) π΅ - Share Distriator project updates π
π How to Load .env Values in React (Vite-based)
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
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 valuesetBusinesses: to update the state
Simple & elegant π
π How to Use useEffect (AKA: βWhy is my API Calling TWICE?!β)
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 π
π― Removing StrictMode is a fix...
But letβs be real β not the best one!
Turns out, the smarter way is to use AbortController to clean up async functions.
And yeah... itβs a bit 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 π
βοΈ Screenshot above highlights just one fileβs worth of changes, but the impact is massive!
Tagging @ecoinstant &
@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
- I asked ChatGPT/AI to help optimize this post to make it more readable and viewer-friendly.
- Here is the link where you can find both original content & improvements made by AI
- https://chatgpt.com/share/6888bbac-21dc-8000-ba70-26940b53cfe7
π My Contributions to β¦οΈ Hive Ecosystem
| Contribution | To | Hive | Ecosystem |
|---|---|---|---|
| Hive Witness Node | Hive API Node (in progress) | 3Speak Video Encoder Node Operator (highest number of nodes) | 3Speak Mobile App Developer |
| 3Speak Podcast App Developer | 3Speak Shorts App Developer | 3Speak Support & Maintenance Team | Distriator Developer |
| CheckinWithXYZ | Hive Inbox | HiFind | Hive Donate App |
| Contributed to HiveAuth Mobile App | Ecency β 3Speak Integration | Ecency β InLeo Integration | Ecency β Actifit Integration |
| Hive Stats App | Vote for Witness App | HiveFlutterKit | New 3Speak App |
π Support Back
β€οΈ Appreciate my work? Consider supporting @threespeak &
@sagarkothari88! β€οΈ
| Vote | For | Witness |
|---|---|---|
| sagarkothari88 | ||
| threespeak |
Leave Day 4 ReactJS Adventures + Distriator Progress: useState, useEffect, and .env Chaos πΉ to:
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
- HiveSuite Dev Update: Bookmarks, Backend Improvements & Development Workflow Enhancement
- HiveSuite Dev Update: Advanced Bookmark System & Video Progress Experience.
- HiveSuite Dev Update: Reward Popup Accuracy, Translation Fixes & Video Progress Improvements
- HiveReactKit Dev Update: Universal Bookmarking & Improved Draft Management
- HiveReactKit Dev Update: Translation Controls, Mobile Safe Areas & IPFS Media Rendering
- HiveSuite Dev Update: Push Notifications, Scheduling Improvements & Draft Reliability
- HiveSuite Dev Update: Drafts Workspace, Scheduled Posts & Push Notification Support
- HiveSuite Dev Update: Community Subscription Integration, Comment Media Fixes & Faster Local Develop
- HiveSuite App & HiveReactKit Development Update for today
- HiveSuite Dev Update: Introducing Word Finder β A Daily Hive Word Puzzle