Skip to content

Instantly share code, notes, and snippets.

View shemseddine's full-sized avatar

Shems Eddine Boukhatem shemseddine

View GitHub Profile
export const useOnForegroundFocus = (
onFocus: () => void,
runOnStartup: boolean | undefined = false
) => {
const appState = useRef(AppState.currentState);
useEffect(() => {
const subscription = AppState.addEventListener('change', (nextAppState) => {
if (
appState.current.match(/inactive|background/) &&
@shemseddine
shemseddine / route-example2.js
Created July 13, 2022 07:39
celebrate/joi body and query validation
app.post(
"/bulk-edit",
celebrate({
body: Joi.object({
title: Joi.string().required().min(8).max(240),
description: Joi.string().required().min(8)
}),
query: Joi.object({
type: Joi.string()
})
@shemseddine
shemseddine / route-example.js
Created July 13, 2022 07:30
an example of an express route using joi/celebrate
app.post(
"/signin",
celebrate({
body: Joi.object({
email: Joi.string().required().email(),
password: Joi.string().required().min(8)
})
}),
(req, res) => {
// ...
import React from 'react';
const Layout : React.FC = () => {
const { mode, setMode } = useTheme();
return <div style={{ background: mode === "light" ? "#fff" : "#000", color: mode === "light" ? "#000" : "#fff" }} >
<h1>Welcome!</h1>
<button onClick={() => setMode(mode === "light" ? "dark" : "light")}>
toggle theme
</button>
import React from 'react';
import { ThemeProvider } from './theme-provider';
import Layout from './layout';
const App : React.FC = () => {
return <ThemeProvider>
<Layout />;
</ThemeProvider>;
}
import React, { createContext, useContext, useState, PropsWithChildren } from "React";
type modeType = "light" | "dark";
interface ThemeState {
mode: modeType;
setMode(mode: modeType): void;
}
const defaultThemeState : ThemeState = {
export const usePerson = () => {
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const fullName = `${firstName} ${lastName}`
return { fullName, setFirstName, setLastName }
}
import React from "react";
import { StyleSheet, Text, View, Button, Alert } from "react-native";
import { AuthSession } from "expo";
import jwtDecode from "jwt-decode";
const auth0_client_id = "[YOUR_AUTH0_CLIENT_ID]";
const auth0_domain = "[YOUR_AUTH0_DOMAIN]";
const toQueryString = params => {
@shemseddine
shemseddine / App.js
Last active October 12, 2021 06:54
react-beautiful-dnd simple multiple dynamic list move example.
import React, { useState } from "react";
import { DragDropContext, Draggable, Droppable } from "react-beautiful-dnd";
function App() {
const [data, updateData] = useState({
backlog: [1, 3, 5, 6, 7, 8, 9],
todo: [2, 4],
doing: [10, 11, 12],
done: []
});
@shemseddine
shemseddine / App.js
Last active August 6, 2019 08:47
react-beautiful-dnd simple two list move example.
import React, { useState } from "react";
import { DragDropContext, Draggable, Droppable } from "react-beautiful-dnd";
function App() {
const [items, updateItems] = useState([1, 2, 3, 4, 5]);
const [selected, updateSelected] = useState([6, 7, 8]);
const reorder = (list, startIndex, endIndex) => {
const result = Array.from(list);
const [removed] = result.splice(startIndex, 1);