Skip to content

Instantly share code, notes, and snippets.

@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',
@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 / 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 / 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) {
const [articleId, setArticleId] = useState(2);
const [articleRequest, abortArticleRequest] = useGetSingleArticle({articleId: articleId});
const abortFuncs = useRef([]);
@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',
@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, {