Skip to content

Instantly share code, notes, and snippets.

View josuerodcat90's full-sized avatar
👨‍💻
Never Stop Learning

Josue Rodriguez josuerodcat90

👨‍💻
Never Stop Learning
View GitHub Profile
//this code snippet solve the problem with frontend refresh when you write the cache with PostForm:
//in Home.js use this:
const [posts, setPosts] = useState([]);
const { user } = useContext(AuthContext);
const { loading, data } = useQuery(FETCH_POSTS_QUERY);
useEffect(() => {
if (data) {
setPosts(data.getPosts);
}
@zoonderkins
zoonderkins / fix-home.js
Created September 14, 2019 15:34
Fix-Home-JS-classed-React GraphQL App (MERNG): #3 Displaying Posts
import React from 'react'
import { useQuery } from '@apollo/react-hooks'
import gql from 'graphql-tag'
import { Grid, Divider } from 'semantic-ui-react'
import PostCard from '../components/PostCard'
function Home() {
let posts = ''
const { loading, data } = useQuery(FETCH_POSTS_QUERY)
@JamieMason
JamieMason / group-objects-by-property.md
Created September 14, 2018 07:38
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
@markthiessen
markthiessen / getWeeksInMonth.js
Last active April 25, 2024 02:05
JavaScript - get weeks in a month as array of start and end days
//note: month is 0 based, just like Dates in js
function getWeeksInMonth(year, month) {
const weeks = [],
firstDate = new Date(year, month, 1),
lastDate = new Date(year, month + 1, 0),
numDays = lastDate.getDate();
let dayOfWeekCounter = firstDate.getDay();
for (let date = 1; date <= numDays; date++) {
@ksafranski
ksafranski / Common-Currency.json
Last active April 22, 2024 15:16
Common Currency Codes in JSON
{
"USD": {
"symbol": "$",
"name": "US Dollar",
"symbol_native": "$",
"decimal_digits": 2,
"rounding": 0,
"code": "USD",
"name_plural": "US dollars"
},