Skip to content

Commit

Permalink
Merge pull request #36 from kinotio/develop
Browse files Browse the repository at this point in the history
feat: use memo on computed value from fetched data in contributors and products
  • Loading branch information
andostronaut authored Jul 23, 2024
2 parents a4d57d4 + 227f4a0 commit 9febf8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions components/layout/sections/contributors.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { useEffect, useState, memo } from 'react'
import { useEffect, useState, memo, useMemo } from 'react'
import { GithubIcon } from 'lucide-react'
import Link from 'next/link'

Expand All @@ -22,6 +22,8 @@ export const ContributorsSection = () => {
.finally(() => setLoading(false))
}, [])

const memorizedContributors = useMemo(() => contributors, [contributors])

return (
<section id="contributors" className="container py-24 sm:py-32">
<div className="text-center mb-8">
Expand All @@ -48,7 +50,7 @@ export const ContributorsSection = () => {
</>
) : (
<>
{contributors.map((contributor) => (
{memorizedContributors.map((contributor) => (
<Contributor key={contributor.id} contributor={contributor} />
))}
</>
Expand Down
6 changes: 4 additions & 2 deletions components/layout/sections/products.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { useState, useEffect, memo } from 'react'
import { useState, useEffect, memo, useMemo } from 'react'
import Image from 'next/image'
import Link from 'next/link'
import { GithubIcon } from 'lucide-react'
Expand All @@ -27,6 +27,8 @@ export const ProductsSection = () => {
.finally(() => setLoading(false))
}, [])

const memorizedRepos = useMemo(() => repos, [repos])

return (
<section id="products" className="container py-24 sm:py-32">
<div className="text-center mb-8">
Expand Down Expand Up @@ -63,7 +65,7 @@ export const ProductsSection = () => {
</>
) : (
<>
{repos.map((repo) => (
{memorizedRepos.map((repo) => (
<Product key={repo.id} repo={repo} />
))}
</>
Expand Down

0 comments on commit 9febf8c

Please sign in to comment.