This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useState } from 'react'; | |
| /** | |
| * Debounce a value to avoid constant calls to the server | |
| * @param value it can be a string or a number | |
| * @param delay the amount in milliseconds that will be delayed | |
| * @returns The give value debounced | |
| */ | |
| export default function useDebounceValue<T>(value: T, delay: number): T { | |
| const [debouncedValue, setDebouncedValue] = useState<T>(value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function removeDuplicates(arr, prop){ | |
| return arr.filter((obj, index, self) => { | |
| return index === self.findIndex((t) => { | |
| return t[prop] === obj[prop] | |
| }) | |
| }) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function onInputChange(file) { | |
| // convert image file to base64 string | |
| const reader = new FileReader(); | |
| reader.addEventListener( | |
| 'load', | |
| () => { | |
| setInputImg(reader.result); | |
| }, | |
| false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const createImage = url => { | |
| return new Promise((resolve, reject) => { | |
| const image = new Image(); | |
| image.addEventListener('load', () => resolve(image)); | |
| image.addEventListener('error', error => reject(error)); | |
| image.setAttribute('crossOrigin', 'anonymous'); | |
| image.src = url; | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState } from 'react' | |
| import Cropper from 'react-easy-crop' | |
| import { getCroppedImg } from '../../../utils/helpers' | |
| export default function ImageCropper({ getBlob, inputImg, fileName }){ | |
| const [crop, setCrop] = useState({ x: 0, y: 0 }) | |
| const [zoom, setZoom] = useState(1) | |
| const onCropComplete = async (_, croppedAreaPixels) => { | |
| const croppedImage = await getCroppedImg( | |
| inputImg, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Africa/Abidjan | |
| Africa/Accra | |
| Africa/Addis_Ababa | |
| Africa/Algiers | |
| Africa/Asmara | |
| Africa/Asmera | |
| Africa/Bamako | |
| Africa/Bangui | |
| Africa/Banjul | |
| Africa/Bissau |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function countingValleys(steps, path) { | |
| for (let index = 0; index < steps; index++) { | |
| const currentStep = path[index]; | |
| const nextStep = path[index + 1]; | |
| let downHill = 0; | |
| let upHill = 0; | |
| if (currentStep + nextStep !== "UD") { | |
| if (currentStep === nextStep) { | |
| // we are either going downhill or uphill | |
| // now check if currentStep is D which means downhil, if U then upHill |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as actions from "../actions/"; | |
| import * as types from "../utils/types"; | |
| import { moviesMock } from "../utils/moviemock"; | |
| describe("actions", () => { | |
| it("should create an action to fetch popular movies", () => { | |
| const fetchMovieAction = { | |
| type: types.FETCH_POPULAR_MOVIES, | |
| movies: moviesMock | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createContext, useContext, useState } from "react"; | |
| // Consumer | |
| // useContext | |
| const AppContext = createContext(); | |
| const ThemeContext = createContext(); | |
| export default function App() { | |
| const [language, setLanguage] = useState("en-US"); | |
| const [color, setColor] = useState("blue"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState } from 'react' | |
| import { Button } from '@chakra-ui/react' | |
| const initialState = { | |
| age: 0, | |
| name: '', | |
| address: '', | |
| phoneNumber: '', | |
| location: '', | |
| } |