๐ 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
.env
in 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 | @sagarkothari88 | |
threespeak | @threespeak |