Skip to content

Instantly share code, notes, and snippets.

Avatar
🍺

Richard Zilahi zilahir

🍺
View GitHub Profile
View tags.js
function handleTagClick(tag, thisLevel) {
reduxDispatch(getContentByTagId(tag.tag_id, authToken))
setLastClickedTag(tag)
const childTagIds = tag.relations.relation
const isRendered = tagState[thisLevel + 2]
if (isRendered) {
const tempTagState = tagState
Object.keys(tagState).map(curr => {
if (curr > thisLevel + 1) {
setTimeout(() => {
View guide.md

React Guide

Table Of Contents

  1. Components
  2. Development Environment
  3. Deployment
  4. General rules 4.1 Hooks 4.2 Project structure
View findInDeepArray.js
/**
* @param {number} tagId the id of the tags we are looking for it's child
* @param {Array} tags array of the level we are looking for the child tags
* @returns {object} object of the found child object
*/
function findTagById(tagId, tags) {
// console.debug("findTagById > Tags", tags);
const result = filter(tags, { item: [{ tag_id: tagId }] });
// console.debug("findTagById > result", result);
return result[0].item.filter(t => t.tag_id === tagId)[0];
@zilahir
zilahir / index.js
Created Apr 23, 2020
routeTransition
View index.js
import React from 'react'
import { AnimatePresence } from 'framer-motion'
import { useSelector } from 'react-redux'
import { Route, Switch, useLocation, Redirect } from 'react-router-dom'
import { MountTransition } from '../MountTransition'
export const RouteTransition = ({
children,
exact = false,
path,
View useStructure.js
import { useState, useCallback } from 'react'
import { useStore } from 'react-redux'
export const useStructure = param => {
const store = useStore()
const fetchedStructure = store.getState().fetchStructure.structure
return {
structure,
setStructure,
getParentTagList: useCallback(tagId => setStructure(
View form.js
import React, { useState } from 'react';
import { submitForm } from '../../store/actions/submitForm'
import Success from '../common/Success';
const ContactForm = () => {
const [name, setName] = useState('')
const [email, setEmail] = useState('')
const [message, setMessage] = useState('')
const [isAnimationHidden, showAnimation] = useState(true)
const [counter, setCounter] = useState(null)
@zilahir
zilahir / Home.js
Created Feb 17, 2020
fetchData with props
View Home.js
/* eslint-disable react/prop-types */
/* eslint-disable no-unused-vars */
/* eslint-disable no-console */
import React, { useState, useEffect } from 'react'
import { api } from '../api'
import { useServerData } from '../state/serverDataContext'
import Cover from './Cover'
import Header from './Header'
import styles from '../styles/root/Root.module.scss'
@zilahir
zilahir / getDaysInMonth.js
Created Jan 12, 2020
get all day iin a month
View getDaysInMonth.js
const d = new Date()
const currentYear = d.getFullYear()
const months = Array(12).fill().map((e,i) => i)
// console.debug('currentYear', currentYear)
// console.debug(months)
const getDaysInMonth = (month, year) => (new Array(31)).fill('').map((v,i)=>new Date(year,month-1,i+1)).filter(v=>v.getMonth()===month-1)
console.debug(getDaysInMonth(1, currentYear))
View uses
# Uses
## Editor
- [Visual Studio Code](https://code.visualstudio.com/download) (settings [here](https://gist.github.com/diurivj/ca5222271a32336273ac1c5a168e8166))
- [lucy](https://marketplace.visualstudio.com/items?itemName=juliettepretot.lucy-vscode) editor theme by [juliettepretot](https://marketplace.visualstudio.com/publishers/juliettepretot)
- [Dank Mono](https://dank.sh/) font by [Phil Plückthun](https://twitter.com/_philpl)
## Chrome Extensions
- [JSON Viewer](https://chrome.google.com/webstore/detail/json-viewer/gbmdgpbipfallnflgajpaliibnhdgobh)
- [React Developer Tools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi)
@zilahir
zilahir / pre-commit.sh
Created Jan 5, 2020
prevent commit to master branch
View pre-commit.sh
#!/bin/sh
branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "$branch" = "master" ]; then
echo "You can't commit directly to master branch"
exit 1
fi
You can’t perform that action at this time.