Skip to content

Commit

Permalink
refactor hook to hooks folder
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepistrol committed Feb 27, 2023
1 parent 29fa810 commit 8c5e822
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
13 changes: 2 additions & 11 deletions components/pages/home/sections/HeroSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 (
<Parallax
Expand Down
17 changes: 17 additions & 0 deletions hooks/useLatestVersionNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useEffect, useState } from 'react';

const useLatestVersionNumber = () => {
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;

0 comments on commit 8c5e822

Please sign in to comment.