Skip to content

Instantly share code, notes, and snippets.

View Sachin-chaurasiya's full-sized avatar
:octocat:
Learning and Contributing

Sachin Chaurasiya Sachin-chaurasiya

:octocat:
Learning and Contributing
View GitHub Profile
@Sachin-chaurasiya
Sachin-chaurasiya / hashnode-blog.yml
Last active September 1, 2024 04:39
Workflow with GitHub action to fetch and display your latest blog from Hashnode in a visually pleasing manner
name: 'Hashnode Blogs'
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Runs every hour, on the hour.
jobs:
update_blogs:
name: 'Hashnode Latest Blogs'
@Sachin-chaurasiya
Sachin-chaurasiya / useAutoSizeTextArea.ts
Last active July 20, 2024 00:48
A simple custom hook to automatically resize the text area based on the content
import { useLayoutEffect } from 'react';
const useAutoSizeTextArea = (
id: string,
textAreaRef: HTMLTextAreaElement | null,
value: string
) => {
// this will calculate the height of textArea before DOM paints
useLayoutEffect(() => {
const textArea = textAreaRef ?? document.getElementById(id);
@Sachin-chaurasiya
Sachin-chaurasiya / useClipBoard.ts
Created March 19, 2023 06:57
Custom hook for copy to clipboard functionality
import { useCallback, useEffect, useState } from 'react';
/**
* React hook to copy text to clipboard
* @param value the text to copy
* @param timeout delay (in ms) to switch back to initial state once copied.
* @param callBack execute when content is copied to clipboard
*/
export const useClipboard = (
value: string,
@Sachin-chaurasiya
Sachin-chaurasiya / useElementInView.js
Last active June 10, 2022 12:27
Use this hook to check if element is in viewport or not.
import { useEffect, useRef, useState } from 'react';
export const useElementInView = (options) => {
const elementRef = useRef(null);
const [isInView, setIsInView] = useState(false);
const handleObserve = (entries) => {
const [entry] = entries;
@Sachin-chaurasiya
Sachin-chaurasiya / spread-operator.js
Last active January 16, 2022 11:20
JavaScript Spread Operator
// Let's say we have two objects i.e userPersonal and userSocial
// We want to merge these two objects and send the new object to the server.
const userPersonal = {
firstName:"Sachin",
lastName:"Chaurasiya",
email:"sachinchaurasiyachotey87@gmail.com",
}
const userSocial={
@Sachin-chaurasiya
Sachin-chaurasiya / rest-operator.js
Last active September 25, 2022 05:51
JavaScript Rest Operator
// Let's say we have one object i.e developer.
const developer={
name:"Sachin Chaurasiya",
age:22,
githubHandle:"https://github.com/Sachin-chaurasiya",
portfolio:"https://sachinchaurasiya.dev",
blog:"https://blog.sachinchaurasiya.dev"
}