Skip to content

Instantly share code, notes, and snippets.

View sandeshdamkondwar's full-sized avatar
🏠
Working from home

Sandesh Damkondwar sandeshdamkondwar

🏠
Working from home
View GitHub Profile
@sandeshdamkondwar
sandeshdamkondwar / types.proto
Created December 22, 2023 09:26
adaptive ui protos
syntax = "proto3";
// Define a component which is a recursive structure
message Component {
string id = 1;
string description = 2;
string component_id = 3;
int32 component_seq = 4;
string component_type = 5;
repeated Component child_components = 6;
@sandeshdamkondwar
sandeshdamkondwar / demo.tsx
Last active August 6, 2020 09:03
Infinite Scroller React Hook
import React, { useEffect, useState, useRef } from "react";
// Helpers
import { debounce, generateCols, getNoOfCols } from "../../helpers/";
// Hooks
import { useInifiniteScroller } from "../../hooks/useInfiniteScroller";
// Defs
import { IGifItem } from "../../defs/interfaces";
@sandeshdamkondwar
sandeshdamkondwar / package.json
Created June 18, 2020 21:32
Basic Webpack Config for TS setup
{
"name": "webpack-and-typescript",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"serve": "webpack-dev-server",
"build": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
@sandeshdamkondwar
sandeshdamkondwar / package.json
Last active June 18, 2020 21:08
Minimal webpack setup using babel-loader, scss-loader & file-loader
{
"name": "setting_up_webpack4",
"version": "1.0.0",
"description": "setting up webpack4",
"main": "index.js",
"scripts": {
"build": "webpack",
"start:dev": "webpack-dev-server"
},
"repository": {
@sandeshdamkondwar
sandeshdamkondwar / useMemoHookDemo.js
Last active June 18, 2020 20:15
useMemo hook for avoiding unnecessary renderings of child components
import React, { useState, useMemo } from 'react'
function Counter() {
const [counterOne, setCounterOne] = useState(0)
const [counterTwo, setCounterTwo] = useState(0)
const incrementOne = () => {
setCounterOne(counterOne + 1)
}
@sandeshdamkondwar
sandeshdamkondwar / FetchUseReducer.js
Last active June 21, 2023 17:16
Fetch data using useReducer
import React, { useReducer, useEffect } from 'react'
import axios from 'axios'
const initialState = {
loading: true,
error: '',
post: {}
}
const reducer = (state, action) => {
@sandeshdamkondwar
sandeshdamkondwar / styles.css
Created June 17, 2020 19:17 — forked from viclafouch/styles.css
A custom React Hook to help you implement a "light/dark mode" component for your application.
html[data-theme='dark'] {
--text-color: #f0F0F0;
--background-body: #1C1C1C;
--other-var: #111111;
}
html[data-theme='light'] {
--text-color: #111111;
--background-body: #FAFAFA;
--other-var: #ffffff;
@sandeshdamkondwar
sandeshdamkondwar / use-viewport.js
Created June 17, 2020 19:17 — forked from viclafouch/use-viewport.js
A custom React Hook for tracking the window width and to get the current viewport.
// hooks/use-viewport.js
import { useState, useEffect } from 'react'
export const MOBILE = 'MOBILE'
export const TABLET = 'TABLET'
export const DESKTOP = 'DESKTOP'
const getDevice = width => {
if (width < 768) return MOBILE
else if (width < 992) return TABLET
@sandeshdamkondwar
sandeshdamkondwar / use-clipboard-api.js
Created June 17, 2020 19:16 — forked from viclafouch/use-clipboard-api.js
A custom React Hook for writing and reading from the modern clipboard API
// hooks/use-clipboard-api.js
import { useState, useCallback } from 'react'
function useClipboardApi() {
const [content, setContent] = useState(null)
const askPermission = useCallback(async queryName => {
try {
const permissionStatus = await navigator.permissions.query(queryName)
return permissionStatus.state === 'granted'
@sandeshdamkondwar
sandeshdamkondwar / use-page-visibility.js
Created June 17, 2020 19:16 — forked from viclafouch/use-page-visibility.js
A custom React Hook to detect if the page is visible or not.
// hooks/use-page-visibility.js
import { useState, useLayoutEffect } from 'react'
function usePageVisibility() {
const [isPageVisible, setIsPageVisible] = useState(!document.hidden)
useLayoutEffect(() => {
const handleVisibility = () => {
setIsPageVisible(!document.hidden)
}