Skip to content

Instantly share code, notes, and snippets.

View pedroalmeida415's full-sized avatar
🖥️
Coding

Pedro Almeida pedroalmeida415

🖥️
Coding
  • São Paulo/SP
View GitHub Profile
@pedroalmeida415
pedroalmeida415 / useScrollBlock.js
Created April 14, 2022 19:03 — forked from reecelucas/useScrollBlock.js
React hook to enable/disable page scroll
import { useRef } from 'react';
const safeDocument = typeof document !== 'undefined' ? document : {};
/**
* Usage:
* const [blockScroll, allowScroll] = useScrollBlock();
*/
export default () => {
const scrollBlocked = useRef();
@pedroalmeida415
pedroalmeida415 / prettierFormatAll.md
Last active April 7, 2020 23:32
Run prettier on all files in a directory with the given extension(s)
  1. Install prettier
  2. Make a .prettierignore file, and add directories you'd like prettier to not format, for example: **/node_modules
  3. Run prettier --write "**/*.{ts,js,css,html,insertAnyFilesExtensionHere}" **Don't forget the quotes.

You could also add this to your projects package.json under scripts to simply run npm run prettier to format your code before committing it:

` { ...

@pedroalmeida415
pedroalmeida415 / multipleRequests.js
Last active April 6, 2020 17:46
Make 2 or more fully parallel asynchronous requests, handle individual errors and do something if they all succeed
const multipleConcurrentRequests = async (...parameters) => {
// This only works with Async/Await syntax, so it has to be inside an Async function
// Start 2 "jobs" in parallel and wait for both of them to complete
await Promise.all([
(async () =>
await axios.post("request.url", {
someData: dataValue,
}))().catch((error) => {
// Handle this request's error...
console.log(error);