useEffect(() => {
let stopGettingAfterUnmount = false;
const getTodo = async () => {
await axios
.get("/api/todo", {
headers: {
"Content-Type": "application/json",
},
params: { userId },
})
.then((response) => {
if (stopGettingAfterUnmount) return;
setTodos(response.data);
});
};
getTodo();
return () => {
stopGettingAfterUnmount = true;
};
}, [userId]);
const copyArray = (array = []) => JSON.parse(JSON.stringify(array));
const [contacts, setContacts] = useState(copyArray(data));
const [contactsInput, setContactsInput] = useState(copyArray(data));
const getSpecificImage = (breakpoint) => {
switch (breakpoint) {
case 1200:
return <Image src="https://google.com?v=1200" />;
case 600:
return <Image src="https://google.com?v=600" />;
default:
return <Image src="https://google.com?v=default" />;
}
};
const breakpoint = window?.innerWidth;
const imageElement = getImageSpecificImage(breakpoint);
return (
<>
{imageElement}
</>
);
const params = (new URL(document.location)).searchParams;
const shouldLoadScript = params.get('script'); // 'true'
if (shouldLoadScript) {
const script = document.createElement('script');
script.src = 'https://url.com/script.js';
document.head.append(script)
}
getStaticProps can only be exported from a page. You can’t export it from non-page files.
const TaskRegionView = () => {
const isMenuOpenLocalStorageKey = '__isMenuOpen';
const [condition, setCondition] = useState(() => {
const value = localStorage.getItem(isMenuOpenLocalStorageKey);
const isOpen = JSON.parse(value);
if (isOpen === null) return false;
return value;
});
const handleToggleCondition = () => {
setCondition((prev) => {
const state = !prev;
localStorage.setItem(isMenuOpenLocalStorageKey, JSON.stringify(state));
return state;
});
};
...
function updateForm(event){
event.preventDefault();
}
<form action="" onsubmit="updateForm()" method="post">
module.exports = (phase, { defaultConfig }) => {
if (phase === PHASE_DEVELOPMENT_SERVER) {
return {
...defaultConfig,
future: {
webpack5: true,
},
redirects: async () => {
return [
{
source: '/sign-up',
destination: '/signup',
permanent: true,
},
];
},
env: {
test: 'hello',
},
};
}
return {
/* config options for all phases except development here */
};
};