Skip to content

Instantly share code, notes, and snippets.

View sahilrajput03's full-sized avatar
💭
I'm happy these days.

Sahil Rajput sahilrajput03

💭
I'm happy these days.
View GitHub Profile
@sahilrajput03
sahilrajput03 / useFetch.js
Last active October 1, 2020 11:27
This is a react hook for fetching data.
// Usage -
//import {useFetch} from "./useFetch.js";
//const url = "https://raw.githubusercontent.com/ajzbc/kanye.rest/quotes/quotes.json";
//const {data, loading} = useFetch(url);
// --
//Defining hook inside useFetch.js file.
import { useEffect, useState, useRef } from "react";
export const useFetch = (url) => {
const isMounted = useRef(true);
@sahilrajput03
sahilrajput03 / mutable.js(from FUTURE).js
Last active October 5, 2020 09:25
A function which helps easying up un mutating state objects when we need to dispatch new unmutated states to `dispatch` calll. # unmutate
const getMutable = (state) => JSON.parse(JSON.stringify(state)); // This is doer.
const mutableState = getMutable(state);
mutableState.books[0].section[2] = 'Things to be learned in august.';
mutableState.books[1].section[4] = 'Things to be learned in november.';
dispatch(mutableState);
// ----------------------------------------------------------------------------------------------------------
// Antoher simple approach is using closures like immer.js does(but it does some depth comparisons too), for e.g. below is my
@tannerlinsley
tannerlinsley / hooks.js
Created January 25, 2019 17:00
useCancellable, useRefresh combo
const useCancellable = fn => {
const requestRef = useRef(0)
return async (...args) => {
// Keep track of latest promise ID
const id = Date.now()
requestRef.current = id
// Wait for resolution
const res = await fn(...args)
// Source
const MyCompSource = ''
// @source MyCompSource
const MyComp = (
<div>
Hello there!
</div>
)
@tannerlinsley
tannerlinsley / .block
Created April 4, 2018 21:49 — forked from mbostock/.block
Grouped Bar Chart
license: gpl-3.0
@tannerlinsley
tannerlinsley / index.html
Last active October 13, 2020 13:34 — forked from d3noob/.block
Simple bar graph in v4
<!DOCTYPE html>
<meta charset="utf-8">
<style> /* set the CSS */
.bar { fill: steelblue; }
</style>
<body>
<!-- load the d3.js library -->
@sahilrajput03
sahilrajput03 / GitCommitEmoji.md
Created July 13, 2020 14:48 — forked from parmentf/GitCommitEmoji.md
Git Commit message Emoji
// Javascript
import { Render, Router, Route, Redirect, IndexRoute, IndexRedirect } from 'jumpsuit'
Render(state, (
<Router>
<Route path='/' component={Layout}>
<IndexRoute component={Teams} />
<Route path='me' component={Me} />
<Route path='workspaces' component={Workspaces} />
<Route path='invite' component={WorkspaceInvite} />
@iansu
iansu / README.md
Last active March 1, 2021 08:40
Create React App 4.0 Alpha Testing

Create New App

JavaScript Template

npx create-react-app@next --scripts-version=@next --template=cra-template@next my-js-app

TypeScript Template

npx create-react-app@next --scripts-version=@next --template=typescript@next my-ts-app