Skip to content

Instantly share code, notes, and snippets.

View Caayu's full-sized avatar
🏠
Working from home

Caio Henrique Caayu

🏠
Working from home
View GitHub Profile
import { useEffect, useState } from "react";
import { useQuery, useQueryClient } from "react-query";
import { PostDetail } from "./PostDetail";
const maxPostPage = 10;
async function fetchPosts(pageNum) {
const response = await fetch(
`https://jsonplaceholder.typicode.com/posts?_limit=10&_page=${pageNum}`
);
@Caayu
Caayu / Pagination.tsx
Created March 28, 2022 18:42
Pagination
import InfiniteScroll from "react-infinite-scroller";
import { useInfiniteQuery } from "react-query";
import { Species } from "./Species";
const initialUrl = "https://swapi.dev/api/species/";
const fetchUrl = async (url) => {
const response = await fetch(url);
return response.json();
};
import InfiniteScroll from "react-infinite-scroller";
import { useInfiniteQuery } from "react-query";
import { Species } from "./Species";
const initialUrl = "https://swapi.dev/api/species/";
const fetchUrl = async (url) => {
const response = await fetch(url);
return response.json();
};
@Caayu
Caayu / component.tsx
Created March 3, 2022 23:26 — forked from BrianCodeItUp/component.tsx
useContext, useReducer with typescript
import React from 'react';
import { View, Text, Button } from 'react-native';
import styles from './styles'
import { ContextProvider, Context } from './context';
const Compo = () => {
const { type } = useContext(Context);
return (
<View style={styles.container}>
<Text>{type}</Text>
@Caayu
Caayu / Kafka-compose.yml
Created December 15, 2021 16:39 — forked from theguuholi/Kafka-compose.yml
Kafka-compose
`version: '3'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
@Caayu
Caayu / redirects-in-react-router-v6.md
Created November 26, 2021 20:08 — forked from mjackson/redirects-in-react-router-v6.md
Notes on handling redirects in React Router v6, including a detailed explanation of how this improves on what we used to do in v4/5

Redirects in React Router v6

An important part of "routing" is handling redirects. Redirects usually happen when you want to preserve an old link and send all the traffic bound for that destination to some new URL so you don't end up with broken links.

The way we recommend handling redirects has changed in React Router v6. This document explains why.

Background

In React Router v4/5 (they have the same API, you can read about why we had to bump the major version here) we had a <Redirect> component that you could use to tell the router when to automatically redirect to another URL. You might have used it like this:

@Caayu
Caayu / custom-entity-not-found-exception-filter.md
Created October 21, 2021 18:21 — forked from gsusmonzon/custom-entity-not-found-exception-filter.md
Make NestJs returns 404 when EntityNotFoundError exception is thrown

Make NestJs returns 404 when EntityNotFoundError exception is thrown

When using findOrFail() or findOneOrFail() from typeORM, a 500 error is returned if there is no entity (EntityNotFoundError).

To make it returns a 404, use an exception filter as described in https://docs.nestjs.com/exception-filters .

file /src/filters/entity-not-found-exception.filter.ts

@Caayu
Caayu / mix.exs
Created September 15, 2021 12:48 — forked from muziyoshiz/mix.exs
Sample of GraphQL Relay server on Phoenix
# mix.exs
defmodule PhoenixRelaySample.Mixfile do
use Mix.Project
def project do
[app: :phoenix_relay_sample,
version: "0.0.1",
elixir: "~> 1.2",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
{
"editor.fontFamily": "Fira Code",
"editor.fontLigatures": true,
"editor.fontSize": 16,
"editor.lineHeight": 22,
"editor.formatOnSave": true,
"editor.rulers": [
80,
120
],