Syntax | Description |
---|---|
Header | Title |
Paragraph | Text |
This file contains 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 Defer from './Defer'; | |
import Card from './Cefer'; | |
const Component = ({ items }) => { | |
return ( | |
<Defer chunkSize={5}> | |
{items.map(item => <Card key={item.id} item={item} />)} | |
</Defer> | |
) | |
}; |
This file contains 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 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( |
This file contains 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 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(); |
This file contains 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 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; | |
} |
This file contains 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 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()) |
This file contains 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 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` |
This file contains 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 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()) |
This file contains 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 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: |
This file contains 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 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` | |
}); |
NewerOlder