Skip to content

Instantly share code, notes, and snippets.

@jgthms
jgthms / useeffect_abort.js
Created July 22, 2022 08:16 — forked from bartcis/useeffect_abort.js
Abort signal on initial fetch of API
export const Articles = () => {
const [state, setState] = useState([]);
useEffect(() => {
const abortController = new AbortController();
const {signal} = abortController;
const apiCall = async path => {
try {
const request = await fetch(path, {
@jgthms
jgthms / fetch_hook.js
Created July 22, 2022 08:16 — forked from bartcis/fetch_hook.js
Fetch from API as custom Hook
import {compile} from 'path-to-regexp';
import {GET_ARTICLE_PATH} from './articles-routes';
export const useGetSingleArticle = ({ articleId, abortController = new AbortController()}) => {
const baseUrl = 'https://jsonplaceholder.typicode.com';
const path = baseUrl + compile(GET_ARTICLE_PATH)({articleId});
const { signal, abort } = abortController || {};
const articleRequest = fetch(path, {
signal: signal,
method: 'GET',
const [articleId, setArticleId] = useState(2);
const [articleRequest, abortArticleRequest] = useGetSingleArticle({articleId: articleId});
const abortFuncs = useRef([]);
@jgthms
jgthms / fetchOnClick.js
Created July 22, 2022 08:15 — forked from bartcis/fetchOnClick.js
Function to fetch and update abort functions
const fetchOnClick = async () => {
try {
abortFuncs.current.unshift(abortArticleRequest);
const newArticleRequest = await articleRequest;
const newArticle = await newArticleRequest.json();
setState([...state, newArticle]);
setArticleId(articleId +1);
} catch(e) {
@jgthms
jgthms / abort-signals-ondestory.js
Created July 22, 2022 08:15 — forked from bartcis/abort-signals-ondestory.js
Example aborting of multiple signals on destroy
useEffect(() => {
const abortController = new AbortController();
const {signal} = abortController;
const apiCall = async path => {
try {
const request = await fetch(path, {
signal: signal,
method: 'GET',
});
@jgthms
jgthms / quill.css
Created September 15, 2020 09:20
Quill Background Gradient
.bg {
600% 500%/90% 90% radial-gradient(closest-side,rgba(228,79,79,.7),rgba(228,79,79,0)) no-repeat,600% 180%/90% 90% radial-gradient(closest-side,rgba(228,79,79,.7),rgba(228,79,79,0)) no-repeat,100% 150%/75% 50% radial-gradient(closest-side,rgba(250,250,218,.2),rgba(250,250,218,0)) no-repeat,-400% -100%/90% 80% radial-gradient(closest-side,rgba(250,250,218,.3),rgba(250,250,218,0)) no-repeat,-100% -250%/85% 80% radial-gradient(closest-side,rgba(94,225,249,.8),rgba(94,225,249,0)) no-repeat,-170% 100%/70% 60% radial-gradient(closest-side,rgba(94,225,249,.6),rgba(94,225,249,0)) no-repeat,50% 50%/100% 100% linear-gradient(30deg,#6e10ce 10%,rgba(110,16,206,0) 70%,hsla(0,0%,100%,0) 90%) no-repeat,linear-gradient(144deg,rgba(233,235,104,0),rgba(233,235,104,.3)) no-repeat,linear-gradient(90deg,rgba(104,184,235,.11),rgba(15,216,223,.11)) no-repeat,#fff
}
@jgthms
jgthms / schema.graphql.js
Created July 2, 2020 18:34
Strapi GraphQL find single item by slug
const { sanitizeEntity } = require('strapi-utils');
module.exports = {
query: `
categoryBySlug(slug: String!): Category
`,
resolver: {
Query: {
categoryBySlug: {
resolverOf: 'Category.findOne',
// How to persist the React Redux state store to the browser's localStorage
// Code taken from Dan Abramov's video
// https://egghead.io/lessons/javascript-redux-persisting-the-state-to-the-local-storage
/**
localStorage.js
*/
export const loadState = () => {
try {
const serializedState = localStorage.getItem('state');
@jgthms
jgthms / git-deployment.md
Created October 27, 2019 17:27 — forked from noelboss/git-deployment.md
Simple automated GIT Deployment using Hooks

Simple automated GIT Deployment using GIT Hooks

Here are the simple steps needed to create a deployment from your local GIT repository to a server based on this in-depth tutorial.

How it works

You are developing in a working-copy on your local machine, lets say on the master branch. Most of the time, people would push code to a remote server like github.com or gitlab.com and pull or export it to a production server. Or you use a service like deepl.io to act upon a Web-Hook that's triggered that service.

@jgthms
jgthms / pure_html_css_modal.css
Created June 12, 2019 17:22 — forked from calebporzio/pure_html_css_modal.css
The CSS for the pure HTML/CSS modal I tweeted about.
details summary {
cursor: pointer;
outline: none !important;
display: inline-block;
padding: 8px 12px;
padding-top: 10px;
border-radius: 4px;
overflow: hidden;
background: #F09825;
color: white;