What do you want to save?
Add Code snippet
New code examples
-
Javascript 2022-03-17 02:05:02
redux action to hit api and assign data in stateless component
export function fetchProducts() { return dispatch => { dispatch(fetchProductsBegin()); return fetch("/products") .then(handleErrors) .then(res => res.json()) .then(json => { dispatch(fetchProductsSucc... Add solution -
Other 2022-03-16 10:05:01
bind input value to useState
export function NameForm(props) { const { value:firstName, bind:bindFirstName, reset:resetFirstName } = useInput(''); const { value:lastName, bind:bindLastName, reset:resetLastName } = useInput(''); const handleSubmit = (evt) => { evt.pr... Add solution -
Javascript 2022-02-28 15:15:06
lerp javascript
export function lerp(v0, v1, amt, maxMove = 0, minDiff = 0.0001) { let diff = v1 - v0; if (maxMove > 0) { diff = Math.min(diff, maxMove); diff = Math.max(diff, -maxMove); } if (Math.abs(diff) < minDiff) { return v1; } return v0 + diff * ... Add solution -
Javascript 2022-02-16 12:40:28
can i use redux connect without react
import store from './store'; export function getProtectedThing() { // grab current state const state = store.getState(); // get the JWT token out of it // (obviously depends on how your store is structured) const authToken = state.currentUser.... Add solution -
TypeScript 2021-11-21 07:10:14
react typescript custom hook
export function useLoading() { const [isLoading, setState] = React.useState(false); const load = (aPromise: Promise<any>) => { setState(true); return aPromise.finally(() => setState(false)); }; return [isLoading, load] as const... Add solution -
Other 2021-11-16 09:54:35
file reader in loopback 4
// MyModel.js import fs = require('fs'); import xml = require('xml') import csv = require('csv') export function import(info, callback) { // Get the current database connection. var ds = this.dataSource.connector; // ***********************... Add solution -
Javascript 2021-11-10 13:50:15
vuex-module-decorators nuxt axios
// /utils/api.ts import { NuxtAxiosInstance } from '@nuxtjs/axios' let $axios: NuxtAxiosInstance export function initializeAxios(axiosInstance: NuxtAxiosInstance) { $axios = axiosInstance } export { $axios } ------------------------ // /plugins/axi... Add solution -
Javascript 2021-11-08 21:58:19
js number padding to number of characters
export function padStart(number, digits = 2, emptyDigit = 0) { let length = 0; let n = Math.abs(number); let absoluteNumber = n; do { n /= 10; length++; } while (n >= 1); const prefix = Array(Math.max((digits - length) + 1, 0)).join(emptyDigi... Add solution