useEffect(() => { const ourRequest = Axios.CancelToken.source() // <-- 1st step const fetchPost = async () => { try { const response = await Axios.get(`endpointURL`, { cancelToken: ourRequest.token, // <-- 2nd step }) console.log(response.data) setPost(response.data) setIsLoading(false) } catch (err) { console.log('There was a problem or request was cancelled.') } } fetchPost() return () => { ourRequest.cancel() // <-- 3rd step } }, [])
How to cancel/abort ajax request in axios
Add preact in nextjs
webpack: (config, { isServer }) => {
// config.plugins.push(new webpack.EnvironmentPlugin(myEnv));
if (!isServer) {
Object.assign(config.resolve.alias, {
react: 'preact/compat',
'react-dom/test-utils': 'preact/test-utils',
'react-dom': 'preact/compat',
});
}
return config;
}
Reverse String In Javascript
function check(val) {
let re='';
for(i of val) {
re = i + re;
console.log(re);
}
}
check('nilesh');
let re='';
for(i of val) {
re = i + re;
console.log(re);
}
}
check('nilesh');
Subscribe to:
Posts (Atom)