Skip to content

Instantly share code, notes, and snippets.

View geekdaniels's full-sized avatar
💭
Reactstruck

Olufemi Oladotun Daniel geekdaniels

💭
Reactstruck
View GitHub Profile
@geekdaniels
geekdaniels / media-query.css
Created August 13, 2018 11:24 — forked from gokulkrishh/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS
@geekdaniels
geekdaniels / index.html
Created February 7, 2019 15:57 — forked from taniarascia/index.html
HTML Skeleton file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="author" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
@geekdaniels
geekdaniels / error-handling-with-fetch.md
Created February 1, 2022 10:07 — forked from odewahn/error-handling-with-fetch.md
Processing errors with Fetch API

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
 })
// Axios Globals
axios.defaults.headers.common["X-Auth-Token"] =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
// GET REQUEST
function getTodos() {
// axios({
// method: "get",
// url: "https://jsonplaceholder.typicode.com/todos",
// params: {
// _limit: 5
Intercept Request
Using a request intercept, you can write or execute before it is sent. Check out the below code snippet.
axios.interceptors.request.use(function (request) {
request.headers['Content-Type'] = 'multipart/form-data';
return request;
}, null, { synchronous: true });
view raw.jsx hosted with ❤ by GitHub
Here we have added the contentType header before the request is made. Request interceptors are asynchronous by default, which might cause some delay in Axios request execution. To avoid this, we have used synchronous: true.
@geekdaniels
geekdaniels / gateway.php
Created February 6, 2023 22:41 — forked from igorbenic/gateway.php
How to create a custom WooCommerce Payment Gateway
<?php
// ...
function woo_payment_gateway() {
class Woo_PayPal_Gateway extends WC_Payment_Gateway {
}
}
@geekdaniels
geekdaniels / recoilPersistLocalForage.ts
Created May 24, 2023 07:10 — forked from tomiolah/recoilPersistLocalForage.ts
Recoil effect, which persists + reads Recoil atom state to / from localForage (IndexedDB)
import localforage from 'localforage';
import { AtomEffect, DefaultValue } from 'recoil';
/**
* Recoil module to persist state to storage
*/
export const recoilPersistLocalForage = ({ key = 'recoil-persist' }: { key?: string }): { persistAtom: AtomEffect<any> } => {
if (typeof window === 'undefined') {
return {
persistAtom: () => {},