Skip to content

Instantly share code, notes, and snippets.

@Lysak
Created February 2, 2026 18:41
Show Gist options
  • Select an option

  • Save Lysak/4f491c15c2beec24b001c214287fbf92 to your computer and use it in GitHub Desktop.

Select an option

Save Lysak/4f491c15c2beec24b001c214287fbf92 to your computer and use it in GitHub Desktop.
react-live-coding.ts
import { useState, useEffect } from "react";
const useUserData = (userId) => {
const [user, setUser] = useState(null);
useEffect(() => {
const fetchUser = async () => {
const response = await fetch(`https://api.example.com/users/${userId}`);
const data = await response.json();
setUser(data);
};
fetchUser();
}, [userId]);
return user;
};
export const UserProfile = ({ userId }) => {
const user = useUserData(userId);
const [count, setCount] = useState(0);
const permissionOptions = {
isAdmin: false,
updatesAllowed: true,
notification: true,
};
const handleUpdate = () => {
// Simulating an expensive calculation or update
setCount(count + 1);
console.log("Profile updated for:", user.name);
};
return (
<div>
<h1>{user.name}</h1>
<p>Email: {user.email}</p>
<button onClick={handleUpdate}>Refresh Local State: {count}</button>
<CustomComponent
userName={user.name}
permissionOptions={permissionOptions}
/>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment