Skip to content

Instantly share code, notes, and snippets.

View 3nvi's full-sized avatar

Aggelos Arvanitakis 3nvi

View GitHub Profile

Hello

From markdown

Syntax Description
Header Title
Paragraph Text
import Defer from './Defer';
import Card from './Cefer';
const Component = ({ items }) => {
return (
<Defer chunkSize={5}>
{items.map(item => <Card key={item.id} item={item} />)}
</Defer>
)
};
@3nvi
3nvi / Defer.jsx
Created May 1, 2021 16:16
A way to defer rendering of a big list
const Defer = ({ chunkSize, children }) => {
const [renderedItemsCount, setRenderedItemsCount] = React.useState(chunkSize);
const childrenArray = React.useMemo(() => React.Children.toArray(children), [
children
]);
React.useEffect(() => {
if (renderedItemsCount < childrenArray.length) {
window.requestIdleCallback(
@3nvi
3nvi / use-real-time-query-simple.ts
Last active July 3, 2022 19:11
A simple way to integrate react-query & firebase
import React from 'react';
import { useQuery, useQueryClient, UseQueryOptions } from 'react-query';
import realTimeApi from './real-time-api';
function useRealTimeQuery<Data>(
firebasePathKey: string,
useQueryOptions: UseQueryOptions<Data> = {}
) {
const queryClient = useQueryClient();
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/database';
// This value is the default 403 code from firebase
const PERMISSION_DENIED_STATUS_CODE = 'PERMISSION_DENIED';
export interface RealTimeFetchParams {
path: string;
}
import React from 'react';
import { useHistory } from 'react-router-dom';
const useQuery = ({ url }) => {
const history = useHistory();
const [apiData, setApiData] = React.useState();
React.useEffect(() => {
fetch(url)
.then(data => data.json())
import React from "react";
import { get } from 'lodash';
import { useParams, Link } from "react-router-dom";
import useQuery from './useQuery';
import Page404 from "./Page404";
const DogPage = () => {
const { breed } = useParams();
const { data, statusCode } = useQuery({
url: `https://dog.ceo/api/breed/${breed}/images/random`
import React from 'react';
import { useHistory } from 'react-router-dom';
const useQuery = ({ url }) => {
const history = useHistory();
const [apiData, setApiData] = React.useState();
React.useEffect(() => {
fetch(url)
.then(data => data.json())
import React from 'react';
import { useLocation } from 'react-router-dom';
import { get } from 'lodash';
import Page404 from './Page404';
const ErrorHandler = ({ children }) => {
const location = useLocation();
switch (get(location.state, 'errorStatusCode')) {
case 404:
import React from "react";
import { useParams, Link } from "react-router-dom";
import { get } from 'lodash';
import useQuery from "./useQuery";
const DogPage = () => {
const { breed } = useParams();
const { data } = useQuery({
url: `https://dog.ceo/api/breed/${breed}/images/random`
});