Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

React sub count

import React,{useState} from "react";
import "./styles.css";
import "bootstrap/dist/css/bootstrap.min.css";
import { Button, Form } from "react-bootstrap";

const youtubeChannelId = require('get-youtube-channel-id')

export default function App() {

  const API_KEY = "###yourapikey###"

  const [subscribers,setSubscribers] = useState(null)
  const [views,setViews] = useState(null);
  const [videos,setVideos] = useState(null)

  const [url,setUrl] = useState(null)

  const handleSubmit = async (e) => {

    e.preventDefault()

    const result = await youtubeChannelId(url)
    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)
    })

    

    console.log(result)
    
  }

  

  const handleChange = (e) => {
   
    setUrl(e.target.value)
  }

  return (
    <div className="App">
      <br />
      <br />
      <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>
        <Button variant="primary" type="submit">
          Submit
        </Button>
      </Form>
      You have {subscribers} subscribers
      <br/>
      You have {videos} Videos
      <br/>
      You have {views} Views
    </div>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to do something before every method is run in a class javascript 
Javascript :: how to combine folder for render in express js 
Javascript :: javascript get distance bwetween elements 
Javascript :: send back text from get request in node.js 
Javascript :: Masonry js css 
Javascript :: ERROR in ./node_modules/pretty-format/node_modules/ansi-regex/index.js Module build failed: Error: ENOENT: no such file or directory 
Javascript :: staticDir storybook svg and images not loading 
Javascript :: var = " "; 
Javascript :: firebase check if key exists javascript 
Javascript :: sharepoint javascript get last added item 
Javascript :: Text with prop value is rendered The component renders variable text based on a string prop. We test that the component renders the value of the passed prop. 
Javascript :: remove null from object lodash 
Javascript :: how to set a custom error message to a form in angular 
Javascript :: Angular generate by skipping test files 
Javascript :: how to change div style to full page react 
Javascript :: html5 web component 
Javascript :: circular objects javascript 
Javascript :: gsap cdn not working 
Javascript :: simple form in react native with code 
Javascript :: blockchain.info/pushtx 
Javascript :: How to by pass CORS error locally 
Javascript :: MongoDB Express Find All In Database 
Javascript :: react-spring 
Javascript :: javascript convert string to number with 2 decimal places 
Javascript :: Will yield function Person 
Javascript :: s3 getobject not getting large json object 
Javascript :: Load RequireJS Script 
Javascript :: save slug on schema pre save in node js 
Javascript :: Parsing error: JSX value should be either an expression or a quoted JSX text. 
Javascript :: HSET redis, HINCRBYFLOAT redis 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =