Last active
April 2, 2023 08:52
-
-
Save ameetmadan/56462ec5b380842633d8b1f598701ffc to your computer and use it in GitHub Desktop.
Boilerplate code for SWR hook using IntelliJ WebStorm Live Templates
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 axios from "axios"; | |
// define the fetcher once, export it and use it every where you use useSWR | |
export const fetcher = (url: string) => axios.get(url).then(res => res.data) | |
const YOUR_API_ENDPOINT = ''; | |
const { data, isLoading, error} = useSWR(`${YOUR_API_ENDPOINT}`, fetcher) | |
if (isLoading) return <div><p>loading</p></div> | |
if (error) return <div><p>error</p></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.jetbrains.com/help/webstorm/creating-and-editing-live-templates.html
https://www.jetbrains.com/help/webstorm/template-variables.html