Skip to content

Instantly share code, notes, and snippets.

View jscodelover's full-sized avatar

Manisha Basra jscodelover

View GitHub Profile
import { myFetch } from './myFetch.js';
async function withSuccess() {
const res = await myFetch({ url: 'https://dummyjson.com/todos' })
if (res.message === 'Success') {
console.log('Yieee')
} else {
console.log(res.reason)
}
// package.json
{
"scripts": {
// standalone Jest
"test": "jest --maxWorkers=50%",
"test:watch": "jest --watch --maxWorkers=25%",
"test:ci": "jest --runInBand",
// or with Create React App
"test": "react-scripts test --watchAll=false --maxWorkers=50%",
@jscodelover
jscodelover / hide_and_scroll.scss
Created October 14, 2020 10:53
hide the scroll and still scroll the element
div{
overflow-x: scroll;
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
&::-webkit-scrollbar {
display: none;
}
}
const getBase64 = file => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
reader.readAsDataURL(file);
});
};
async function onChangeFile(e) {
@jscodelover
jscodelover / is_localstorage_accessible.js
Created October 5, 2020 10:33
code to check whether local storage is accessible or not (in case of disabled cookies )
export const accessibleLS = () => {
try {
localStorage.setItem('check', true);
localStorage.removeItem(tcheckest);
return true;
} catch (e) {
return false;
}
};
function cached(fn){
// Create an object to store the results returned after each function execution.
const cache = Object.create(null);
// Returns the wrapped function
return function cachedFn (str) {
// If the cache is not hit, the function will be executed
if ( !cache[str] ) {
let result = fn(str);
@jscodelover
jscodelover / class.js
Created January 10, 2020 10:43
binding class intsance to class method
class A{
constructor(){
this.name= "manisha"
this.demo = this.demo.bind(this);
}
demo(){
const surname = "basra";
return `${this.name} ${surname}`
}
@jscodelover
jscodelover / styled component
Last active January 10, 2020 10:41
to increase the specificity
/* css */
.header {
background: #453434; /* overrided */
}
// JSX
<Div className="header sc-wS45d" />
const Div = styled.div`
&&& {
@jscodelover
jscodelover / onSubmitHook.js
Created October 31, 2019 07:39
custom react hook for submit button.
import React, { useState } from "react";
import ReactDOM from "react-dom";
const useSubmit = submitFunction => {
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const handleSubmit = async () => {
try {
setLoading(true);
import React, { Component } from 'react';
import {
CardElement,
injectStripe,
StripeProvider,
CardNumberElement,
CardExpiryElement,
CardCVCElement,
Elements
} from 'react-stripe-elements';