@stornity Camera could not capture the real beauty which the eyes saw. It looks more beautiful in real bro. One must definitely visit Himalays in their life.
Small update: Updated the UI and added a feature to change the display name, and also learnt a concept called Stale Closure, read till the end to learn about it.
- Today I coded with no internet, which made me give more time to think what logic am I writing and what the bug is happening, and how do I solve it.
- Added a feature where the peer can change their name which will instantly update on every connected peer by updating it through websocket.
Concept: Stale closure - occurs when a function captures an outdated variable from an old scope, failing to see updated values
function Counter() {
const [count, setCount] = React.useState(0);
useEffect(() => {
setInterval(() => {
console.log("Count:", count);
}, 2000);
}, []);
return (
);
}
now you expect the count to go as 0,1,2,3,4,5 as you click. but it wont instead it will be 0,0,0,0 for ever, but why?
when the component first renders, react runs the effect and the setinterval is created, but the funtion captures count as 0, even when react updatesthe state the internal callback still sees the initial value. replay with the solution.
- I was using a zustand state variable inside a useeffect which ran on first component mount, now every time i used the variable inside the effect it was null, but zustand has a better way to solve it by using store.getState() as zustand store is not tied to react and can be accessed anywhere.
DAY 2: worked on the client side ws connection.
- I used to write inline code where I put the logic of ws connection in the useeffct and make a connection, but this had some downsides like ws instance being created on each rerender.
- So I learnt and used a different code
9 Followers 216 FollowingBuilding in public | DSA + Full Stack Dev 🛠️
Day 1 of my 8-month engineering journey
Sharing everything I learn • Mistakes included
📍 India
0 Followers 21 Followingposting about my growth and random thoughts, posting about my daily progress and builds, less shitpost and more knowledge here
- onepiece coz its my fav -
6K Followers 1K FollowingFounder @trywatermelonHQ @xocketHQ
Designing & building products for AI, SaaS & web3.
Working with founders backed by YC, Antler & @a16z.
Building in public.
59K Followers 2K Following@Shopify design-engineer; prior @GoogleChrome, @GoogleCloud, CSSWG, and CSS Podcast. Host on @whiskeywebfm, maker of @OpenProps, https://t.co/lb3SDxC6EC and more