mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 07:25:35 +00:00
Début du projet, création du comportement de base + structure du site / du projet
This commit is contained in:
28
components/Links/Link.js
Normal file
28
components/Links/Link.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import { useEffect, useCallback } from 'react';
|
||||
import { useInView } from 'react-intersection-observer';
|
||||
|
||||
import styles from '../../styles/links.module.scss';
|
||||
|
||||
export default function Link({ category, setCategoryActive, refCategoryActive }) {
|
||||
const { ref, inView } = useInView({ threshold: .5 });
|
||||
const { id, name, links, ref: refCategory } = category;
|
||||
|
||||
useEffect(() => inView ? setCategoryActive(id) : null, [id, inView, setCategoryActive]);
|
||||
|
||||
const setRefs = useCallback((node) => {
|
||||
refCategory.current = node;
|
||||
refCategoryActive.current = node;
|
||||
ref(node);
|
||||
}, [ref, refCategoryActive, refCategory]);
|
||||
|
||||
return (
|
||||
<div className={styles['link-block']} ref={setRefs}>
|
||||
<h2>{name}</h2>
|
||||
<ul className={styles['links']}>
|
||||
{links.map(({ name }, key2) => (
|
||||
<li key={key2} className={styles['item']}>{name}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user