Skip to content

Instantly share code, notes, and snippets.

View MarcosNASA's full-sized avatar
🚀

Marcos S. MarcosNASA

🚀
View GitHub Profile
@MarcosNASA
MarcosNASA / Explanation.md
Last active July 3, 2024 17:25
Avoid `useEffect`s to resynchronize server/local state

The study case

You Might Not Need an Effect has been live for, at the very least, a couple of years now. It has really helped! However, I keep seeing at least one incorrect and widely-spread usage of useEffects: server/local state synchronization.

const Edit = ({ data, onSave }) => {
  const [dynamicData, setDynamicData] = useState(data)
  
  useEffect(() => {
 setDynamicData(data) // Don't do this!
@MarcosNASA
MarcosNASA / ChatGPTVoice.js
Last active December 6, 2022 17:15
Gives ChatGPT a voice
const debounce = (delay) => (fn) => {
let timeoutId;
return (...args) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
fn(...args);
}, delay);
};
};
const speak = (text) => {