Skip to content

Instantly share code, notes, and snippets.

@syJSdev
syJSdev / axios-catch-error.js
Created October 8, 2020 13:47 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@syJSdev
syJSdev / InputBox.js
Created October 28, 2020 01:30
Input component wrapper to prevent cursor jump
import React, { useState, useRef, useEffect } from 'react';
import PropTypes from 'prop-types';
function useRunAfterUpdate() {
const afterPaintRef = React.useRef(null);
React.useLayoutEffect(() => {
if (afterPaintRef.current) {
afterPaintRef.current();
afterPaintRef.current = null;
}
@syJSdev
syJSdev / react-tic-tac-toe.js
Created November 4, 2020 02:59
Tic Tac Toe game built with React.js
import React from "react";
import ReactDOM from "react-dom";
const rowStyle = {
display: "flex",
};
const squareStyle = {
width: "60px",
height: "60px",