From 8c5e822dcd59f676acd7baf3c1d29ed702816d82 Mon Sep 17 00:00:00 2001 From: Lukas Pistrol Date: Mon, 27 Feb 2023 23:10:17 +0100 Subject: [PATCH] refactor hook to `hooks` folder --- components/pages/home/sections/HeroSection.jsx | 13 ++----------- hooks/useLatestVersionNumber.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 hooks/useLatestVersionNumber.js diff --git a/components/pages/home/sections/HeroSection.jsx b/components/pages/home/sections/HeroSection.jsx index a1978fd..63f7b6d 100644 --- a/components/pages/home/sections/HeroSection.jsx +++ b/components/pages/home/sections/HeroSection.jsx @@ -6,7 +6,7 @@ import Typography from '@/components/common/Typography'; import { Row, Column, Section, Stack } from '@/components/common/layout'; import HeroImage from '../HeroImage'; import Button from '../../../common/Button'; -import { useState, useEffect } from 'react'; +import useLatestVersionNumber from '@/hooks/useLatestVersionNumber'; const ProductIconWrap = styled.div` width: 128px; @@ -16,16 +16,7 @@ const ProductIconWrap = styled.div` const HeroSection = () => { - const [data, setData] = useState(null) - const versionNumber = data?.name ?? 'Loading...' - - useEffect(() => { - fetch('https://api.github.com/repos/CodeEditApp/CodeEdit/releases/latest') - .then((res) => res.json()) - .then((data) => { - setData(data) - }) - }, []) + const versionNumber = useLatestVersionNumber(); return ( { + const [versionNumber, setVersionNumber] = useState(); + + useEffect(() => { + fetch('https://api.github.com/repos/CodeEditApp/CodeEdit/releases/latest') + .then((res) => res.json()) + .then((data) => { + setVersionNumber(data.name) + }) + }, []) + + return versionNumber ?? 'Loading...'; +}; + +export default useLatestVersionNumber;