import React, { useState, useEffect, useRef } from 'react'; const App = () => { const videoData = [ { id: 1, title: 'Top 10 Languages', link: 'https://www.youtube.com/watch?v=ehXa1Hxxu3Y', preview: 'https://img.youtube.com/vi/ehXa1Hxxu3Y/maxresdefault.jpg', }, { id: 2, title: 'Something BIG', link: 'https://www.youtube.com/watch?v=lbveOrbHgto', preview: 'https://img.youtube.com/vi/lbveOrbHgto/maxresdefault.jpg', }, { id: 3, title: 'Microsoft Journey', link: 'https://www.youtube.com/watch?v=0mRyTDhxe_s', preview: 'https://img.youtube.com/vi/0mRyTDhxe_s/maxresdefault.jpg', }, { id: 4, title: 'Web Security', link: 'https://www.youtube.com/watch?v=578Pzg7tVF4', preview: 'https://img.youtube.com/vi/578Pzg7tVF4/maxresdefault.jpg', }, { id: 5, title: 'Extract Audio', link: 'https://www.youtube.com/watch?v=SrPi0FrmGiE', preview: 'https://img.youtube.com/vi/SrPi0FrmGiE/maxresdefault.jpg', }, { id: 6, title: 'Graphs DS', link: 'https://www.youtube.com/watch?v=pCmsQVHYXK0', preview: 'https://img.youtube.com/vi/pCmsQVHYXK0/maxresdefault.jpg', }, ]; const [videos, setVideos] = useState(videoData); const inputRef = useRef(); useEffect(() => { const searchFn = () => { const searchVar = inputRef.current.value.toLowerCase(); const filteredVideo = videoData.filter((video) => video.title.toLowerCase().includes(searchVar) ); setVideos(filteredVideo); }; inputRef.current.addEventListener('input', searchFn); return () => { inputRef.current.removeEventListener('input', searchFn); }; }, []); return ( <div> <h1 style={ { color: 'green', textAlign: "center" } }> GeeksforGeeks </h1> <h3 style={{ margin: "5px 5px" }}> Approach 2: Using useRef and useEffect </h3> <input type="text" placeholder="Search videos Here" ref={inputRef} style={ { width: '80%', marginLeft: "10px", padding: '10px', fontSize: '16px', border: "2px solid black" }} /> <ul style={ { listStyle: 'none', padding: 0, display: 'flex', flexWrap: 'wrap' }}> {videos.map((video) => ( <li key={video.id} style={ { margin: '10px', flex: '0 0 30%', minWidth: '200px' }}> <a href={video.link} target="_blank" rel="noopener noreferrer"> <img src={video.preview} alt={video.title} style={{ width: '80%', height: 'auto' }}/> <p>{video.title}</p> </a> </li> ))} </ul> </div> ); }; export default App;