<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Brice VIGNAL</title>
    <description>The latest articles on DEV Community by Brice VIGNAL (@vignalbrice).</description>
    <link>https://dev.to/vignalbrice</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F701722%2Fbbbab850-7f7d-4500-8c73-c5e033004aaa.png</url>
      <title>DEV Community: Brice VIGNAL</title>
      <link>https://dev.to/vignalbrice</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vignalbrice"/>
    <language>en</language>
    <item>
      <title>Creating a Searchable Video List in React</title>
      <dc:creator>Brice VIGNAL</dc:creator>
      <pubDate>Wed, 27 Dec 2023 19:12:52 +0000</pubDate>
      <link>https://dev.to/vignalbrice/creating-a-searchable-video-list-in-react-1ja5</link>
      <guid>https://dev.to/vignalbrice/creating-a-searchable-video-list-in-react-1ja5</guid>
      <description>&lt;p&gt;In this tutorial, we will explore how to build a simple React application that allows users to search through a list of videos. We'll create a basic video list with a search functionality using React's state management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up the React Project
&lt;/h2&gt;

&lt;p&gt;To get started, let's create a new React project using Create React App. Open your terminal and run the following commands:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm create vite searchable-video-list&lt;br&gt;
cd searchable-video-list&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will set up a new React project for you.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating the Video Component
&lt;/h2&gt;

&lt;p&gt;Our first step is to create a component that represents an individual video. Create a file named &lt;strong&gt;Video.js&lt;/strong&gt; with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Video.js
import React from 'react';

const Video = ({ title, url }) =&amp;gt; (
  &amp;lt;div&amp;gt;
    &amp;lt;h3&amp;gt;{title}&amp;lt;/h3&amp;gt;
    &amp;lt;iframe
      title={title}
      width="560"
      height="315"
      src={url}
      frameBorder="0"
      allowFullScreen
    &amp;gt;&amp;lt;/iframe&amp;gt;
  &amp;lt;/div&amp;gt;
);

export default Video;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This component takes title and url as props and displays a simple video player with an iframe.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building the VideoList Component
&lt;/h2&gt;

&lt;p&gt;Next, let's create a VideoList component that will display a list of videos. Create a file named &lt;strong&gt;VideoList.js&lt;/strong&gt; with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// VideoList.js
import React, { useState } from "react";
import Video from "./Video";


const VideoList = ({ videos }) =&amp;gt; {

  return (
      &amp;lt;div
        style={{
          marginTop: 20,
          display: "grid",
          gridTemplateColumns: "repeat(5, 1fr)",
          gap: 20,
        }}
      &amp;gt;
        {videos.map((video) =&amp;gt; (
          &amp;lt;Video key={video.id} {...video} /&amp;gt;
        ))}
      &amp;lt;/div&amp;gt;
  );
};

export default VideoList;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating the SearchInput Component
&lt;/h2&gt;

&lt;p&gt;This component includes a search input that updates the searchTerm state. It then filters the videos based on the search term and displays the filtered videos.&lt;/p&gt;

&lt;p&gt;Create a file named &lt;strong&gt;SearchInput.js&lt;/strong&gt; with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\\ SearchInput.js
import React from "react";

const SearchInput = ({ searchTerm, setSearchTerm }) =&amp;gt; {
  return (
    &amp;lt;input
      type="text"
      placeholder="Search videos"
      value={searchTerm}
      onChange={(e) =&amp;gt; setSearchTerm(e.target.value)}
    /&amp;gt;
  );
};

export default SearchInput;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Integrating Components in the App
&lt;/h2&gt;

&lt;p&gt;Now, let's integrate these components into our main &lt;strong&gt;App.js&lt;/strong&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// App.js
import React from 'react';
import VideoList from './VideoList';
import SearchInput from './SearchInput';

const App = () =&amp;gt; {

  const [searchTerm, setSearchTerm] = useState("");

  const videos = [
    { id: 1, title: 'Video 1', url: 'https://www.youtube.com/embed/VIDEO_ID1' },
    { id: 2, title: 'Video 2', url: 'https://www.youtube.com/embed/VIDEO_ID2' },
    // Add more videos as needed
  ];

  const filteredVideos = videos
.filter((video) =&amp;gt; video.title.toLowerCase()
.includes(searchTerm.toLowerCase()));


  return (
    &amp;lt;div
      style={{
        display: "flex",
        flexDirection: "column",
        alignItems: "center",
        justifyContent: "center",
      }}
    &amp;gt;
      &amp;lt;h1&amp;gt;Searchable Video List&amp;lt;/h1&amp;gt;
      &amp;lt;SearchInput 
        searchTerm={searchTerm} 
        setSearchTerm={setSearchTerm} /&amp;gt;
      &amp;lt;VideoList videos={filteredVideos} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this file, we import the VideoList and SearchInput components and provide a list of video objects as props. The main app component renders the video list with a title.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations! You've built a basic React application with a searchable video list. &lt;/p&gt;

&lt;p&gt;This example demonstrates how React's state management can be leveraged to create dynamic and interactive user interfaces. Feel free to customize and extend this example based on your specific needs, such as fetching video data from an API or adding more details to the video component. Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>react</category>
    </item>
    <item>
      <title>Creating a Searchable Video List in React</title>
      <dc:creator>Brice VIGNAL</dc:creator>
      <pubDate>Wed, 27 Dec 2023 19:12:52 +0000</pubDate>
      <link>https://dev.to/vignalbrice/creating-a-searchable-video-list-in-react-oaj</link>
      <guid>https://dev.to/vignalbrice/creating-a-searchable-video-list-in-react-oaj</guid>
      <description>&lt;p&gt;In this tutorial, we will explore how to build a simple React application that allows users to search through a list of videos. We'll create a basic video list with a search functionality using React's state management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up the React Project
&lt;/h2&gt;

&lt;p&gt;To get started, let's create a new React project using Create React App. Open your terminal and run the following commands:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm create vite searchable-video-list&lt;br&gt;
cd searchable-video-list&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will set up a new React project for you.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating the Video Component
&lt;/h2&gt;

&lt;p&gt;Our first step is to create a component that represents an individual video. Create a file named &lt;strong&gt;Video.js&lt;/strong&gt; with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Video.js
import React from 'react';

const Video = ({ title, url }) =&amp;gt; (
  &amp;lt;div&amp;gt;
    &amp;lt;h3&amp;gt;{title}&amp;lt;/h3&amp;gt;
    &amp;lt;iframe
      title={title}
      width="560"
      height="315"
      src={url}
      frameBorder="0"
      allowFullScreen
    &amp;gt;&amp;lt;/iframe&amp;gt;
  &amp;lt;/div&amp;gt;
);

export default Video;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This component takes title and url as props and displays a simple video player with an iframe.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building the VideoList Component
&lt;/h2&gt;

&lt;p&gt;Next, let's create a VideoList component that will display a list of videos. Create a file named &lt;strong&gt;VideoList.js&lt;/strong&gt; with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// VideoList.js
import React, { useState } from "react";
import Video from "./Video";

type VideoListProps = {
  videos: {
    id: number;
    title: string;
    url: string;
  }[];
};

const VideoList = ({ videos }: VideoListProps) =&amp;gt; {

  return (
      &amp;lt;div
        style={{
          marginTop: 20,
          display: "grid",
          gridTemplateColumns: "repeat(5, 1fr)",
          gap: 20,
        }}
      &amp;gt;
        {videos.map((video) =&amp;gt; (
          &amp;lt;Video key={video.id} {...video} /&amp;gt;
        ))}
      &amp;lt;/div&amp;gt;
  );
};

export default VideoList;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating the SearchInput Component
&lt;/h2&gt;

&lt;p&gt;This component includes a search input that updates the searchTerm state. It then filters the videos based on the search term and displays the filtered videos.&lt;/p&gt;

&lt;p&gt;Create a file named &lt;strong&gt;SearchInput.js&lt;/strong&gt; with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\\ SearchInput.js
import React from "react";

const SearchInput = ({ searchTerm, setSearchTerm }) =&amp;gt; {
  return (
    &amp;lt;input
      type="text"
      placeholder="Search videos"
      value={searchTerm}
      onChange={(e) =&amp;gt; setSearchTerm(e.target.value)}
    /&amp;gt;
  );
};

export default SearchInput;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Integrating Components in the App
&lt;/h2&gt;

&lt;p&gt;Now, let's integrate these components into our main &lt;strong&gt;App.js&lt;/strong&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// App.js
import React from 'react';
import VideoList from './VideoList';
import SearchInput from './SearchInput';

const App = () =&amp;gt; {

  const [searchTerm, setSearchTerm] = useState("");

  const videos = [
    { id: 1, title: 'Video 1', url: 'https://www.youtube.com/embed/VIDEO_ID1' },
    { id: 2, title: 'Video 2', url: 'https://www.youtube.com/embed/VIDEO_ID2' },
    // Add more videos as needed
  ];

  const filteredVideos = videos
.filter((video) =&amp;gt; video.title.toLowerCase()
.includes(searchTerm.toLowerCase()));


  return (
    &amp;lt;div
      style={{
        display: "flex",
        flexDirection: "column",
        alignItems: "center",
        justifyContent: "center",
      }}
    &amp;gt;
      &amp;lt;h1&amp;gt;Searchable Video List&amp;lt;/h1&amp;gt;
      &amp;lt;SearchInput 
        searchTerm={searchTerm} 
        setSearchTerm={setSearchTerm} /&amp;gt;
      &amp;lt;VideoList videos={filteredVideos} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this file, we import the VideoList and SearchInput components and provide a list of video objects as props. The main app component renders the video list with a title.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations! You've built a basic React application with a searchable video list. &lt;/p&gt;

&lt;p&gt;This example demonstrates how React's state management can be leveraged to create dynamic and interactive user interfaces. Feel free to customize and extend this example based on your specific needs, such as fetching video data from an API or adding more details to the video component. Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>react</category>
    </item>
  </channel>
</rss>
