Youtube Subscriber Count in ReactJs

In this tutorial i’m going to learn how to count YouTube Subsribers count, views count as well, as define below.

In order to install your app, first go to your workspace (desktop or a folder) and run the following command:

Go to your visual code and open terminal there as below.

npx create-react-app my-app

Next step go to your my-app

After the installation is completed, change to the directory where your app was installed:

cd my-app

and finally run npm start to see your app live on localhost:

npm start

Next First install bootstrap in react

npm install react-bootstrap bootstrap

Now simply copy and paste below code in App.js

Firs’t run below command

npm i get-youtube-channel-idnpm i react-bootstrap

and next go to App.js and simply paste below code.

import React, { useState } from "react";import "bootstrap/dist/css/bootstrap.min.css";import Container from "react-bootstrap/Container";import { Button, Form } from "react-bootstrap";const youtubeChannelId = require("get-youtube-channel-id");export default function App() {  const [url, setUrl] = useState(null);  const [subscribers, setSubscribers] = useState(null);  const [views, setViews] = useState(null);  const [videos, setVideos] = useState(null);  const API_KEY = "AIzaSyDmTojFDOFUpjlr6e-lnKT5sHBn5UD2bOI";  const handleChange = (e) => {    setUrl(e.target.value);  };  async function handleSubmit(e) {    e.preventDefault();    const result = await youtubeChannelId(url);    console.log(result.id);    fetch(      `https://www.googleapis.com/youtube/v3/channels?part=statistics&id=${result.id}&key=${API_KEY}`    )      .then((data) => data.json())      .then((result) => {        console.log(result);        setSubscribers(result.items[0].statistics.subscriberCount);        setViews(result.items[0].statistics.viewCount);        setVideos(result.items[0].statistics.videoCount);      });  }  return (    <div>      <br />      <br />      <Container>        <div          style={{            display: "flex",            justifyContent: "center",            alignItems: "center",            height: "12vh",            color: "red"          }}        >          <h2> Enter your channel url </h2>        </div>        <Form onSubmit={handleSubmit}>          <Form.Group controlId="channelUrl">            <Form.Label>Channel URL:</Form.Label>            <Form.Control              type="text"              name="url"              onChange={handleChange}              value={url}              required              placeholder="Enter Channel URL"            />          </Form.Group>          <br />          <Button variant="primary" type="submit">            Submit          </Button>          <br />        </Form>        You have {subscribers} subscribers        <br />        You have {videos} Videos        <br />        You have {views} Views      </Container>    </div>  );}

Run this command

npm rebuildnpm start

Now you can see your code is running well.

Next put your YouTube Channel url in input box.

Thanks please comment and like….👍👍

Related Posts

Understanding Event Correlation Tools in DataOps: Complete Guide

Introduction Modern enterprise data architectures run hundreds of pipelines every day. Data flows continuously from relational databases, cloud stores, third-party APIs, and streaming brokers into analytical data…

Read More

How AI Enhances DataOps Platforms: The Ultimate Guide to Intelligent Data

Introduction Modern enterprises are generating unprecedented volumes of data across distributed cloud data platforms, SaaS applications, operational databases, and edge devices. Extracting real-time, high-value insights from these…

Read More

DataOps Tools for Continuous Integration and Delivery: A Step-by-Step Blueprint

Introduction In the modern enterprise landscape, data is no longer merely an analytical byproduct of operations—it is the primary driver of strategic decisions, real-time customer experiences, and…

Read More

The Complete SEO Playbook for AI Guest Post Generation and Publishing

Introduction Search engine optimization relies heavily on authority, relevance, and trust. While search algorithms continually evolve, securing high-quality backlinks through strategic content placement remains a foundational ranking…

Read More

Top Digital Marketing Workflow Management Tools for Agencies

Introduction Managing a modern digital marketing stack often feels like juggling dozens of disconnected software subscriptions. Marketing managers, agency owners, and SEO specialists frequently find themselves jumping…

Read More

AI Prompt Management Tools: From Basic Prompts to High-Value Digital Assets

Generative artificial intelligence has fundamentally altered how modern enterprises, creative teams, and technical engineers operate. However, as organizations increase their reliance on large language models (LLMs), a…

Read More