Skip to content

Instantly share code, notes, and snippets.

import React, { useReducer } from 'react';
function reducer(state, action) {
switch (action.type) {
case 'add':
return [...state, action.item];
case 'remove':
return [
...state.slice(0, action.index),
...state.slice(action.index + 1)
in package.json
"scripts": {
"dploy": "func() { git add . && git commit -m \"mess - $1\" && git push; }; func",
}
in terminal
npm run dploy -- "message here"
import axios from "axios"
export async function handler(event, context) {
try {
const response = await axios.get("https://icanhazdadjoke.com", { headers: { Accept: "application/json" } })
const data = response.data
return {
statusCode: 200,
body: JSON.stringify({ msg: data.joke })
}
} catch (err) {
const list = new Array(5000).fill(0).map((v, i) => i);
Si err = HOC import TypeError: Object(…) is not a function
soluce =
import {ContextHoc} from "../../context/ContextHoc"
Gatsby node > pages by locales + add i18n to context
Page layout context > locales
component Switch lang
{variableTrue
? (
<div>
bla bla
</div>
)
: (
undefined
)}
pb synchro pubsub, n'écoute plus par ex
ajouter un token
this.OPEN_OVERLAY = PubSub.subscribe("OPEN_OVERLAY", this._toggle)
PubSub.unsubscribe(this.OPEN_OVERLAY)
[1, 2, 3].forEach((val) => console.log(val));
getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}