uz
Feedback
ToCode

ToCode

Kanalga Telegramโ€™da oโ€˜tish

ื˜ื™ืคื™ื ืงืฆืจื™ื ืœืžืชื›ื ืชื™ื ืžืืช ื™ื ื•ืŸ ืคืจืง

Ko'proq ko'rsatish
1 420
Obunachilar
+124 soatlar
+17 kunlar
-430 kunlar
Postlar arxiv
ToCode
1 420
ืคื•ื˜ื ืฆื™ืืœ (ื˜ื™ืค ืœื—ื™ืคื•ืฉ ืขื‘ื•ื“ื”) ืœืคืขืžื™ื ืื ื™ ืื—ืคืฉ ืขื‘ื•ื“ื” ืฉื‘ื“ื™ื•ืง ืžืชืื™ืžื” ืœื›ื™ืฉื•ืจื™ื ืฉืœื™. ื‘ืžืฆื‘ ื›ื–ื” ืื ื™ ืฆืจื™ืš ืœืฉื›ื ืข ืืช ื”ืžืขืกื™ืง ืฉืื ื™ ืžื›ื™ืจ ืืช ื”ื—ื•ืžืจ ื•ืžืกื•ื’ืœ ืœื‘ืฆืข ืืช ื”ืžื˜ืœื•ืช ื‘ืฆื•ืจื” ื”ื˜ื•ื‘ื” ื‘ื™ื•ืชืจ. ืœืขืชื™ื ื™ื•ืชืจ ืงืจื•ื‘ื•ืช ืื ื™ ืื—ืคืฉ ืขื‘ื•ื“ื” ืฉืชืงื“ื ืื•ืชื™, ืขื‘ื•ื“ื” ืฉืื ื™ ืขื“ื™ื™ืŸ ืœื ื™ื•ื“ืข ืื™ืš ืœื‘ืฆืข ืื‘ืœ ืื ื™ ื—ื•ืฉื‘ ืฉืื•ื›ืœ ืœื’ื“ื•ืœ ืœืฉื. ื‘ืžืฆื‘ ื›ื–ื” ื”ืืชื’ืจ ื”ื•ื ืœืฉื›ื ืข ืืช ื”ืžืขืกื™ืง ืฉื™ืฉ ืœื™ ืืช ื”ืคื•ื˜ื ืฆื™ืืœ ืœื”ืฆืœื™ื— ืœืขืฉื•ืช ืืช ื”ืžืขื‘ืจ (ืžืžืชื›ืช ืœืžื ื”ืœ, ืž QA ืœืžืชื›ื ืช, ืžืžืชื›ื ืช ืœืคืจื•ื“ืงื˜, ืื• ื›ืœ ืžืขื‘ืจ ืื—ืจ ืฉืืชื ื—ื•ืœืžื™ื ืขืœื™ื•). ื›ืŸ ื–ื” ื”ื›ื™ ืงืœ ืœืฉื›ื ืข ื‘ืชื•ืš ื”ืืจื’ื•ืŸ ืื‘ืœ ืืคืฉืจ ื’ื ืœืฉื›ื ืข ืื ืฉื™ื ื–ืจื™ื. ื›ืžื” ื“ื‘ืจื™ื ืฉื”ื™ื™ืชื™ ืžื ืกื” ื‘ืžืฆื‘ ื›ื–ื”- 1. ืœื”ื‘ืœื™ื˜ ื‘ืงื•ืจื•ืช ื—ื™ื™ื ืืช ื”ื“ื‘ืจื™ื ื”ื˜ื•ื‘ื™ื ืฉืขืฉื™ืชื ื‘ืกื˜ื˜ื•ืก ื”ื ื•ื›ื—ื™ ืื• ืืช ื”ืคืจื•ื™ืงื˜ื™ื ืฉื‘ื™ืฆืขืชื ื‘ื”ืฆืœื—ื”. 2. ืœื”ืชื—ื™ืœ ืืช ื”ืชื”ืœื™ืš, ืื‘ืœ ืœื”ื™ื–ื”ืจ ืขื ื”ืฆื’ืช ืชื•ืฆืจื™ื (ืžื™ ืฉื”ื™ื” 5 ืฉื ื™ื ืžืชื›ื ืช ื•ืจืง ื”ืชื—ื™ืœ ืœืคื ื™ ื—ื•ื“ืฉื™ื™ื ืงื•ืจืก UI/UX ืื•ืœื™ ืœื ื™ืฆืจ ืขื“ื™ื™ืŸ ืืช ื”ืขื™ืฆื•ื‘ื™ื ื”ื›ื™ ืžื˜ื•ืจืคื™ื). 3. ืœื”ื‘ืœื™ื˜ ืฉื™ื ื•ื™ื™ื ืžืงืฆื•ืขื™ื™ื ืงื•ื“ืžื™ื ืฉืขืฉื™ืชื, ืจืฆื•ื™ ื‘ืžื›ืชื‘ ืžืงื“ื™ื ื”ืžืฆื•ืจืฃ ืœืงื•ืจื•ืช ื”ื—ื™ื™ื. 4. ืœื”ื™ื•ืช ืžื•ื›ื ื™ื ืœืชืงื•ืคืช ื”ื›ืฉืจื” ืื• ื™ืจื™ื“ื” ื‘ืฉื›ืจ. ืœื ืœื‘ื•ื ื‘ื“ืจื™ืฉื•ืช. 5. ืœื”ืชื—ื™ืœ ื‘ืงื˜ืŸ - ืชื•ืš ื›ื“ื™ ื”ื—ื™ืคื•ืฉ ืฉื•ื•ื” ืœืžืฆื•ื ืžืงื•ืžื•ืช ื‘ืชืคืงื™ื“ ื”ื ื•ื›ื—ื™ ืื• ืืคื™ืœื• ื‘ื”ืชื ื“ื‘ื•ืช ื‘ื”ื ืืชื ื™ื›ื•ืœื™ื ืœืขืฉื•ืช ืืช ื”ื“ื‘ืจ ืฉืืชื ืจื•ืฆื™ื ืœืขืฉื•ืช. ืื•ืชื• ืžืชื›ื ืช ื™ื•ื›ืœ ืœื‘ื ื•ืช ืขื™ืฆื•ื‘ื™ UI/UX ืœืืคืœื™ืงืฆื™ื•ืช ื“ืžื™ื•ื ื™ื•ืช ืื• ื‘ื”ืชื ื“ื‘ื•ืช. ืœื ื‘ื˜ื•ื— ืฉื”ื™ื™ืชื™ ืžืฆืจืฃ ืื•ืชื ืœืงื•ืจื•ืช ื—ื™ื™ื ืื‘ืœ ื›ืŸ ืฉื™ื”ื™ื” ืžืฉื”ื• ืœื“ื‘ืจ ืขืœื™ื• ื‘ืจืื™ื•ืŸ. ื”ื“ื‘ืจ ื”ื—ืฉื•ื‘ ื‘ืฉื›ื ื•ืข ื”ื•ื ืœื”ืจืื•ืช ืฉืืชื ืžื‘ื™ื ื™ื ืืช ื”ืืชื’ืจ ื•ืฉื›ื•ืœื ืžื“ื‘ืจื™ื ื‘ืื•ืชื” ืฉืคื”. ื‘ืชื•ืจ ืžืขืกื™ืง ื”ื™ื™ืชื™ ืžืคื—ื“ ืœืชืช ืฆ'ืื ืก ืœืžื™ ืฉื”ืชื—ื™ืœ ืœืคื ื™ ื—ื•ื“ืฉื™ื™ื ืงื•ืจืก ืขื™ืฆื•ื‘ ืื‘ืœ ื›ื‘ืจ ืžืชื ื”ื’ ื›ืžื• ืžืขืฆื‘-ืขืœ. ืื‘ืœ ืื ื”ื‘ืŸ ืื“ื ืžื‘ื™ืŸ ืฉื”ื•ื ืขื“ื™ื™ืŸ ืจื—ื•ืง ืžื”ื™ืขื“ ืื‘ืœ ืžืคื•ืงืก ื‘ื“ืจืš ืœืฉื, ื•ืžืจืื” ืฉื”ื•ื ืขืฉื” ืฉื™ื ื•ื™ื™ื ื“ื•ืžื™ื ื‘ืขื‘ืจ ื•ืžื•ื›ืŸ ืœืืชื’ืจ, ื•ืื ื™ ืžืื•ื“ ืฆืจื™ืš ืžืขืฆื‘ ื•ื›ื‘ืจ ืžื™ื•ืืฉ ืžืœืžืฆื•ื ืื—ื“ ืขื ื ื™ืกื™ื•ืŸ, ื™ืฉ ืกื™ื›ื•ื™ ืฉืืงื— ืืช ื”ืกื™ื›ื•ืŸ ื•ืืชืŸ ืืช ื”ื”ื–ื“ืžื ื•ืช.

ToCode
1 420
playerRef.current = YouTubePlayer(playerDivRef.current);
      playerRef.current.loadVideoById(videoId);  
    }
  }, [])

  const changeVideoId = (e) => {
    const videoId = e.target.value;
    setVideoId(videoId);
    
    const player = playerRef.current;
    if (player) {
      player.loadVideoById(videoId);
    }
  }

  return (
    <div>
      <div>
        <button onClick={() => playerRef.current.playVideo()}>Play</button>
        <button onClick={() => playerRef.current.pauseVideo()}>Pasue</button>
        <div>
          <input type="text" value={videoId} onChange={changeVideoId} />
        </div>
        <div ref={playerDivRef}></div>
      </div>
    </div>
  )
}

function Toggle() {
  const [hidden, setHidden] = useState(false);
  return (
    <div>
      <input type="checkbox" checked={hidden} onChange={() => setHidden(v => !v)} /> Hide
      {hidden ? <></> : <YoutubePlayerComponent />}
    </div>
  )
}
export default Toggle

ToCode
1 420
playerRef.current.loadVideoById(videoId);
    }
  }, [])
ืื ื™ ืœื ืื•ื”ื‘ ืืช ื–ื” ื›ื™ ื™ืฉ ืคื” ืืคืงื˜ ื‘ืœื™ ืคื•ื ืงืฆื™ื™ืช ื ื™ืงื•ื™ ื•ื–ื” ื ืจืื” ื›ืžื• ืžืฉื”ื• ืฉื”ื•ืœืš ืœื”ื™ืฉื‘ืจ ื‘ืงืจื•ื‘, ืื‘ืœ ืžืื—ืจ ื• youtube-player ืžืขื“ื›ืŸ ืืช ื” DOM ื‘ืœื™ ืœืฉืื•ืœ ืื•ืชื ื• ื–ืืช ืกื•ื’ ืฉืœ ืคืฉืจื” ืฉืื™ ืืคืฉืจ ืœื”ืชื—ืžืง ืžืžื ื”. ืื™ืš ืœืฉื‘ื•ืจ ืื•ืชื” ืื—ืจื™ ืฉืฉื™ืœื‘ื ื• ื”ืกื™ื‘ื” ื”ืžืจื›ื–ื™ืช ืฉืื ื™ ืœื ืื•ื”ื‘ ืืช ื”ืžื ื’ื ื•ืŸ ื”ื™ื ื”ื”ื ื—ื” ื”ื ืกืชืจืช ืฉื”ื•ื ื›ื•ืœืœ - ื”ืžืขืงืฃ ื›ื•ืœืœ ื”ื ื—ื” ืกืžื•ื™ื” ืœืคื™ื” ืืœืžื ื˜ ื”ื ื’ืŸ ืœืขื•ืœื ืœื ื™ืฉืชื ื” ื›ืชื•ืฆืื” ืžืฉื™ื ื•ื™ื™ื ื‘ืกื˜ื™ื™ื˜. ื–ื” ื”ื›ืจื—ื™ ื‘ืฉื‘ื™ืœ ืฉ youtube-player ืชืขื‘ื•ื“, ืฉื•ื‘ ื‘ื’ืœืœ ืฉ youtube-player ืžืฉื ื” ืืช ื” DOM. ืื ืื ื—ื ื• ืžื ืกื™ื ืœืขื“ื›ืŸ ืืช ื”ืงื•ืžืคื•ื ื ื˜ื” ื•ื›ืŸ ืœืฉื ื•ืช ืืช ื” DOM ืžืชื•ืš ืจื™ืืงื˜ ื™ืฉ ื”ืชื ื’ืฉื•ืช. ืฉื™ืžื• ืœื‘ ืœื’ื™ืจืกื” ื”ืฉื‘ื•ืจื” ื”ื–ืืช:
import { useEffect, useRef, useState } from 'react'
import YouTubePlayer from 'youtube-player'

const YoutubePlayerComponent = () => {
  const [videoId, setVideoId] = useState('efGw88Wlncw');
  const [hidden, setHidden] = useState(false);
  const playerDivRef = useRef(null);
  const playerRef = useRef(null);

  useEffect(() => {
    if (!playerRef.current) {
      playerRef.current = YouTubePlayer(playerDivRef.current);
      playerRef.current.loadVideoById(videoId);  
    }
  }, [])

  const changeVideoId = (e) => {
    const videoId = e.target.value;
    setVideoId(videoId);
    
    const player = playerRef.current;
    if (player) {
      player.loadVideoById(videoId);
    }
  }


  return (
    <div>
      <div>
        <input type="checkbox" checked={hidden} onChange={() => setHidden(v => !v)} /> Hide
        <button onClick={() => playerRef.current.playVideo()}>Play</button>
        <button onClick={() => playerRef.current.pauseVideo()}>Pasue</button>
        <div>
          <input type="text" value={videoId} onChange={changeVideoId} />
        </div>
        {hidden ? <></> : <div ref={playerDivRef}></div>}        
      </div>
    </div>
  )
}
export default YoutubePlayerComponent
ื”ื›ืคืชื•ืจื™ื ืขื•ื‘ื“ื™ื ืื‘ืœ ืื ืื ื™ ืžื ืกื” ืœืœื—ื•ืฅ ืขืœ hide ื”ื›ืœ ื ืขืœื ื•ืžื•ืคื™ืขื” ื”ื•ื“ืขืช ืฉื’ื™ืื” ื‘ืงื•ื ืกื•ืœ:
react-dom.development.js:12056 Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
    at removeChild (http://localhost:5173/node_modules/.vite/deps/react-dom_client.js?v=782b4cde:8467:26)
    at commitDeletionEffectsOnFiber (http://localhost:5173/node_modules/.vite/deps/react-dom_client.js?v=782b4cde:17506:21)
    at commitDeletionEffects (http://localhost:5173/node_modules/.vite/deps/react-dom_client.js?v=782b4cde:17473:13)
    at recursivelyTraverseMutationEffects (http://localhost:5173/node_modules/.vite/deps/react-dom_client.js?v=782b4cde:17670:17)
    at commitMutationEffectsOnFiber (http://localhost:5173/node_modules/.vite/deps/react-dom_client.js?v=782b4cde:17733:15)
    at recursivelyTraverseMutationEffects (http://localhost:5173/node_modules/.vite/deps/react-dom_client.js?v=782b4cde:17681:15)
    at commitMutationEffectsOnFiber (http://localhost:5173/node_modules/.vite/deps/react-dom_client.js?v=782b4cde:17733:15)
    at recursivelyTraverseMutationEffects (http://localhost:5173/node_modules/.vite/deps/react-dom_client.js?v=782b4cde:17681:15)
    at commitMutationEffectsOnFiber (http://localhost:5173/node_modules/.vite/deps/react-dom_client.js?v=782b4cde:17695:15)
    at recursivelyTraverseMutationEffects (http://localhost:5173/node_modules/.vite/deps/react-dom_client.js?v=782b4cde:17681:15)
ืจื™ืืงื˜ ืžื ืกื” ืœืžื—ื•ืง ืืช ื”ื ื’ืŸ ืื‘ืœ ืžื’ืœื” ืฉื–ื” ืœื ื”ื•ื ืฉื”ื•ืกื™ืฃ ืืช ื”ื ื’ืŸ ื•ืœื›ืŸ ืžื—ืœื™ื˜ ืœื”ื™ืฉื‘ืจ. ื ื•, ืจืื™ื ื• ืืช ื–ื” ื‘ื ื›ืฉ youtube-player ื”ื—ืœื™ื˜ื” ืœืฉื ื•ืช ืืช ื” DOM ืื– ืงืฉื” ืืคื™ืœื• ืœื›ืขื•ืก ืขืœื™ื•. ืื ื‘ื›ืœ ื–ืืช ืื ื—ื ื• ืžืชืขืงืฉื™ื ืœื”ื•ืกื™ืฃ ืžื ื’ื ื•ืŸ ืฉืœ Toggle ื ืฆื˜ืจืš ืœื‘ื ื•ืช ืื•ืชื• ื‘ืชื•ืš ืงื•ืžืคื•ื ื ื˜ื” ื—ื™ืฆื•ื ื™ืช ืœื ื’ืŸ ื”ื•ื™ื“ืื•, ื•ืืช ื–ื” ืจื™ืืงื˜ ื›ื‘ืจ ื™ืกื›ื™ื ืœืงื‘ืœ:
import { useEffect, useRef, useState } from 'react'
import YouTubePlayer from 'youtube-player'

const YoutubePlayerComponent = () => {
  const [videoId, setVideoId] = useState('efGw88Wlncw');
  const playerDivRef = useRef(null);
  const playerRef = useRef(null);

  useEffect(() => {
    if (!playerRef.current) {

ToCode
1 420
ื‘ื•ืื• ื ืฉื‘ื•ืจ ืงืฆืช ืจื™ืืงื˜ ืœืจื™ืืงื˜ ื™ืฉ ื›ืžื” ืงื•ื ืกืคื˜ื™ื ืคืฉื•ื˜ื™ื ืฉืจื•ื‘ ื”ื–ืžืŸ ืžืฆืœื™ื—ื™ื ืœื”ื—ื–ื™ืง ืžืขืจื›ืช ืื‘ืœ ืœืคืขืžื™ื ื’ื ืžื‘ื™ืื™ื ืื•ืชื ื• ืœืงืฆื•ื•ืช ืฉืœ ืชืกื›ื•ืœ. ื–ื” ืชืžื™ื“ ืงื•ืจื” ื›ื™ ืฉื‘ืจื ื• ืื™ื–ื” ื›ืœืœ ืจื™ืืงื˜ื™ ืื™ืŸ ืกืคืง, ืื‘ืœ ื‘ื—ื™ื™ื ืงืฉื” ืœืขื‘ื•ื“ ืจืง ืœืคื™ ื”ื›ืœืœื™ื. ื‘ื•ืื• ื ื™ืงื— ืœื“ื•ื’ืžื” ืืช ื”ืกืคืจื™ื” youtube-player ืž npm. ืžื” ืฉื‘ื•ืจ ื‘ืกืคืจื™ื” ื”ืกืคืจื™ื” youtube-player ื ื•ืชื ืช ืžืžืฉืง ืงืœ ืœืขื‘ื•ื“ื” ืขื ื” API ืฉืœ ื™ื•ื˜ื™ื•ื‘. ืื ื—ื ื• ื ื•ืชื ื™ื ืœื” ื‘ื‘ื ืื™ ืืœืžื ื˜ DOM ื•ื”ื™ื ื™ื•ืฆืจืช ื‘ืชื•ื›ื• ื ื’ืŸ ื™ื•ื˜ื™ื•ื‘ ืขื ืื™ื™ืคืจื™ื™ื ื•ื”ื›ืœ. ื‘ืฉื‘ื™ืœ ืœื”ืฉืชืžืฉ ื‘ื” (ืžืชื•ืš ื”ืชื™ืขื•ื“ ืฉืœื”ื) ืฆืจื™ืš ืจืง ืœื›ืชื•ื‘:
let player;

player = YouTubePlayer('video-player');

// 'loadVideoById' is queued until the player is ready to receive API calls.
player.loadVideoById('M7lc1UVf-VE');

// 'playVideo' is queue until the player is ready to received API calls and after 'loadVideoById' has been called.
player.playVideo();
ื”ืกื•ืก ื”ื˜ืจื•ื™ืื ื™ ื›ืืŸ ื”ื•ื ืฉืจื™ืืงื˜ ืžืื•ื“ ืœื ืื•ื”ื‘ ืฉืžื™ืฉื”ื• ืื—ืจ ืžืฉื ื” ืœื• ืืช ื” DOM, ื•ืขื•ื“ ืžืขื˜ ื”ื•ื ื™ืชืขื•ืจืจ ื•ื™ืชืจื’ื–. ื ื™ืกื™ื•ืŸ ืจืืฉื•ืŸ ืœืฉืœื‘ ืืช ื”ืกืคืจื™ื” ืขื ืจื™ืืงื˜ ื™ื›ื•ืœ ืœื”ื™ืจืื•ืช ื›ืš-
import { useEffect, useRef, useState } from 'react'
import YouTubePlayer from 'youtube-player'

const YoutubePlayerComponent = () => {
  const [videoId, setVideoId] = useState('efGw88Wlncw');
  const playerDivRef = useRef(null);
  const playerRef = useRef(null);

  useEffect(() => {
    playerRef.current = YouTubePlayer(playerDivRef.current);
    playerRef.current.loadVideoById(videoId);
  }, [])

  const changeVideoId = (e) => {
    const videoId = e.target.value;
    setVideoId(videoId);
    
    const player = playerRef.current;
    if (player) {
      player.loadVideoById(videoId);
    }
  }


  return (
    <div>
      <div>
        <button onClick={() => playerRef.current.playVideo()}>Play</button>
        <button onClick={() => playerRef.current.pauseVideo()}>Pasue</button>
        <div>
          <input type="text" value={videoId} onChange={changeVideoId} />
        </div>
        <div ref={playerDivRef}></div>
      </div>
    </div>
  )
}
export default YoutubePlayerComponent
ื™ื•ืฆืจื™ื ืงื•ืžืคื•ื ื ื˜ื”, ื‘ืขืœื™ื™ื” ืฉืœ ื”ืงื•ืžืคื•ื ื ื˜ื” ื™ื•ืฆืจื™ื ืืช ื”ื ื’ืŸ ื•ืื– ื›ืœ ืคืขื ืฉืžืฉืชื ื” ื”ืžื–ื”ื” ืฉืœ ื”ื•ื™ื“ืื• ื˜ื•ืขื ื™ื ืืช ื”ื•ื™ื“ืื• ื”ื—ื“ืฉ ื“ืจืš ื”ื ื’ืŸ. ืืคืฉืจ ื’ื ืœื”ื•ืกื™ืฃ ื›ืคืชื•ืจื™ื ืฉืœ "ื ื’ืŸ" ื•"ื”ืคืกืง" ื‘ืงื•ื“ ื”ืงื•ืžืคื•ื ื ื˜ื”. ื”ืงื•ื“ ื ืจืื” ื ื›ื•ืŸ ืื‘ืœ ื”ื•ื ืœื ืขื•ื‘ื“. ื”ื›ืคืชื•ืจื™ื ืœื ืžืชืคืงื“ื™ื. ืงืœ ืœืจืื•ืช ืฉื”ื‘ืขื™ื” ื”ื™ื ื‘ืืคืงื˜ ืฉื™ื•ืฆืจ ืืช ื”ื ื’ืŸ. ื‘ื“ืจืš ื›ืœืœ ืืคืงื˜ื™ื ืฆืจื™ื›ื™ื ืœื›ืœื•ืœ ืงื•ื“ "ื ื™ืงื•ื™", ื›ืœื•ืžืจ ื”ืืคืงื˜ ื”ื•ื ื—ื™ื‘ื•ืจ ืœืžืฉื”ื• ื—ื™ืฆื•ื ื™ ื• useEffect ืฆืจื™ื›ื” ืœื”ื—ื–ื™ืจ ืคื•ื ืงืฆื™ื” ืฉืžื‘ื˜ืœืช ืืช ื”ื—ื™ื‘ื•ืจ ื”ื–ื”. ื‘ืžืงืจื” ืฉืœื ื• ืื™ืŸ ื“ืจืš ืœื ืงื•ืช ืืช ื”ื—ื™ื‘ื•ืจ ื›ื™ ื”ืกืคืจื™ื” youtube-player ืœื ืžืกืคืงืช ื›ื–ื•. ื”ื™ื ื›ืŸ ืžืฆื™ืขื” ืคื•ื ืงืฆื™ื” ืืกื™ื ื›ืจื•ื ื™ืช ื‘ืฉื destroy, ืื‘ืœ ื”ืืกื™ื ื›ืจื•ื ื™ื•ืช ืฉืœ ื”ืคื•ื ืงืฆื™ื” ื”ื™ื ื‘ืขื™ื™ืชื™ืช. ื”ืคื•ื ืงืฆื™ื” ืžืกื™ืจื” ืžื” DOM ืืช ื”ืืœืžื ื˜ ืฉืœ ื”ื ื’ืŸ ื‘ืฆื•ืจื” ืืกื™ื ื›ืจื•ื ื™ืช, ื•ืœื›ืŸ ืขืœื•ืœื” ืœื”ืกื™ืจ ืื•ืชื• ื”ืจื‘ื” ืื—ืจื™ ืฉื”ืืคืงื˜ ื‘ื•ื˜ืœ. ื‘ืžืœื™ื ืื—ืจื•ืช ืื ืื ื™ ืžื ืกื” ืœื”ื•ืกื™ืฃ ืืช ืงื•ื“ ื”ื ื™ืงื•ื™ ื”ื–ื”:
  useEffect(() => {
    playerRef.current = YouTubePlayer(playerDivRef.current);
    playerRef.current.loadVideoById(videoId);
    return () => {
      playerRef.current.destroy();
    }
  }, [])

ื”ืงื•ื“ ื™ื™ืฆื•ืจ ืืช ื” iframe ื‘ืฉื‘ื™ืœ ื”ื ื’ืŸ ื•ืื– ืžื™ื“ ื™ืžื—ืง ืื•ืชื•. ืžื” ืฉืงื•ืจื” ื›ืืŸ ื–ื” ืฉื‘ืžืฆื‘ ืคื™ืชื•ื— ืจื™ืืงื˜ ืžืคืขื™ืœ ืืช ื”ืืคืงื˜ ื•ืื– ืžืจื™ืฅ ืืช ืงื•ื“ ื”ื ื™ืงื•ื™ ืฉืœื• ื•ืื– ืžืคืขื™ืœ ืืช ื”ืืคืงื˜ ืฉื•ื‘. ื–ืืช ื‘ื“ื™ืงื” ืฉืœ ืจื™ืืงื˜ ืฉื ื•ืขื“ื” ืœื•ื•ื“ื ืฉืืคืฉืจ ืœื‘ื˜ืœ ื•ืœื”ื—ื–ื™ืจ ืืช ื”ืืคืงื˜ ื‘ืœื™ ื‘ืขื™ื”, ืื‘ืœ ื‘ืžืงืจื” ืฉืœื ื• ื–ื” ืœื ืขื•ื‘ื“ ื›ื™ ื”ืžื—ื™ืงื” ื”ื™ื ืืกื™ื ื›ืจื•ื ื™ืช. ืคื•ื ืงืฆื™ื™ืช destroy ืชื•ืคืขืœ ืื—ืจื™ ืฉืจื™ืืงื˜ ืžื‘ื˜ืœ ืืช ื”ืืคืงื˜ ื•ืžื—ื–ื™ืจ ืื•ืชื• ื•ืื– ืชืžื—ืง ืืช ื”ืื™ื™ืคืจื™ื™ื ืฉืœ ื”ื ื’ืŸ ื”ืฉื ื™. ืื•ืชื” ื”ืชื ื”ื’ื•ืช ื”ื™ื ื’ื ื–ืืช ืฉื’ืจืžื” ืœื›ืคืชื•ืจื™ื ืœื ืœืขื‘ื•ื“, ืื‘ืœ ืžืกื™ื‘ื” ืื—ืจืช. ื›ืฉืจื™ืืงื˜ ืžื’ื™ืข ืœื”ืคืขื™ืœ ืืช ื”ืืคืงื˜ ืคืขื ืฉื ื™ื” ื”ื•ื ื™ื•ืฆืจ ื ื’ืŸ ื—ื“ืฉ ืฉื“ื•ืจืก ืืช ื”ื ื’ืŸ ื”ืงื•ื“ื. ื”ื ื’ืŸ ื”ืจืืฉื•ืŸ ื”ื•ื ื–ื” ืฉืžืชืคืงื“ ืื‘ืœ ื”ื›ืคืชื•ืจื™ื ืžืคืขื™ืœื™ื ืืช ื”ืคื•ื ืงืฆื™ื•ืช play ื• pause ืฉืœ ื”ื ื’ืŸ ื”ื—ื“ืฉ ืฉืœื ื‘ืืžืช ืžื—ื•ื‘ืจ ืœืื™ื™ืคืจื™ื™ื. ืื™ืš ื‘ื›ืœ ื–ืืช ืœืฉืœื‘ ืื•ืชื” ื‘ืคืจื•ื™ืงื˜ ืจื™ืืงื˜ ื‘ืžืฆื‘ื™ื ื›ืืœื” ืื• ืื ื—ื ื• ืื• ืจื™ืืงื˜ ื ืฆื˜ืจืš ืœื”ืชืคืฉืจ, ื•ืœืฆืขืจื™ ื‘ืขื‘ื•ื“ื” ืขื ืจื™ืืงื˜ ื–ื” ืื ื—ื ื• ืฉืฆืจื™ื›ื™ื ืœื•ื•ืชืจ. ื”ืคื™ืชืจื•ืŸ ื”ืขืฆื•ื‘ ื”ื•ื ืœื‘ื“ื•ืง ื‘ืงื•ื“ ื”ืืคืงื˜ ืื ื”ื ื’ืŸ ื›ื‘ืจ ืงื™ื™ื, ื•ืื ื›ืŸ ืœื ืœื™ืฆื•ืจ ื—ื“ืฉ. ื–ื” ื ืจืื” ื›ืš:
  useEffect(() => {
    if (!playerRef.current) {
      playerRef.current = YouTubePlayer(playerDivRef.current);

ToCode
1 420
ืื™ืš ืœื–ื”ื•ืช ืชื™ืจื•ืฆื™ื ืœืื™ ื”ืชืงื“ืžื•ืช ืžืงืฆื•ืขื™ืช ื™ืฉ ื”ืžื•ืŸ ืกื™ื‘ื•ืช ื˜ื•ื‘ื•ืช ืœื”ืชืจื—ืง ืžื˜ื›ื ื•ืœื•ื’ื™ื” ื—ื“ืฉื” ื›ืžื• ืœืžืฉืœ- 1. ืื ื™ ื›ื‘ืจ ืžืžืฉ ื˜ื•ื‘ ื‘ X, ื‘ืฉื‘ื™ืœ ืžื” ืœื‘ื–ื‘ื– ืืช ื”ื–ืžืŸ ืขืœ Y. 2. ืื™ืŸ ืœื™ ืฆื•ืจืš ื‘ื–ื” ืœืขื‘ื•ื“ื” ืฉืœื™. 3. ื–ื” ื”ื›ืœ ื”ื™ื™ืค, ืชื›ืฃ ื”ื”ืชืœื”ื‘ื•ืช ืชื™ื’ืžืจ ื•ื›ื•ืœื ื™ื—ื–ืจื• ืœื˜ื›ื ื•ืœื•ื’ื™ื” ืฉื”ื™ืชื” ืงื•ื“ื. 4. ืื™ืŸ ืžืกืคื™ืง ืื ืฉื™ื ื‘ืชืขืฉื™ื™ื” ืฉืžืฉืชืžืฉื™ื ื‘ Y ื•ื—ื‘ืœ ืœื™ ืœื‘ื–ื‘ื– ืืช ื”ื–ืžืŸ ืขืœ ืžืฉื”ื• ืฉืœื ื™ืงื“ื ืื•ืชื™. 5. ื”ื™ื™ืชื™ ืฉืžื— ืœืœืžื•ื“ ืืช Y ืื‘ืœ ื›ืจื’ืข ืื ื—ื ื• ื‘ื“ื™ื•ืง ื‘ืืžืฆืข ืคืจื•ื™ืงื˜, ืื—ืจื™ ื”ื’ื™ืจืกื” ืืชื—ื™ืœ ืœื”ืกืชื›ืœ ืขืœ ื–ื”. ื•ื”ืžื•ืŸ ืคืขืžื™ื ื”ืกื™ื‘ื•ืช ื”ืืœื” ืžืžืฉ ื ื›ื•ื ื•ืช. ื™ืฉ ืชืงื•ืคื•ืช ื‘ื—ื™ื™ื ืฉืœื ืฆืจื™ืš ืœืœืžื•ื“ ืฉื•ื ื“ื‘ืจ ื—ื“ืฉ ื•ื”ื“ื‘ืจ ื”ื—ืฉื•ื‘ ื”ื•ื ืœื”ืชืงื“ื ื‘ืคืจื•ื™ืงื˜ ื”ืžื“ื”ื™ื ืฉืื ื—ื ื• ื‘ื•ื ื™ื. ืื ื›ืœ ื”ื™ื•ื ื”ื™ื™ื ื• ืœื•ืžื“ื™ื ื˜ื›ื ื•ืœื•ื’ื™ื•ืช ื—ื“ืฉื•ืช ืœื ื”ื™ื” ื–ืžืŸ ืœืขื‘ื•ื“. ื”ื‘ืขื™ื” ื”ื™ื ืฉืœืคืขืžื™ื ืžื” ืฉื ืฉืžืข ื›ืžื• ืกื™ื‘ื” ืžืžืฉ ื˜ื•ื‘ื” ื”ื•ื ื‘ืขืฆื ืชื™ืจื•ืฅ ืฉืžืจื’ื™ืฉ ื›ืžื• ืกื™ื‘ื”. ืชื™ืจื•ืฅ ืฉืžืชื—ื–ื” ื›ืœ ื›ืš ื˜ื•ื‘ ืฉืืคื™ืœื• ื”ื‘ืŸ ืื“ื ืฉื ื•ืชืŸ ืื•ืชื• ืœื ืžืฆืœื™ื— ืœืฉื™ื ืœื‘ ืฉื™ืฉ ืคื” ืžืฉื”ื• ื—ืฉื•ื“. ื˜ืจื™ืง ืื—ื“ ืฉืขื•ื‘ื“ ื‘ืฉื‘ื™ืœื™ ื›ื“ื™ ืœื–ื”ื•ืช ืžืชื™ ืื ื™ ื‘ืืžืช ืขืกื•ืง ืžื“ื™ ื•ืžืชื™ ืื ื™ ืจืง ืžืชื—ืžืง ื”ื•ื ืœื”ืืจื™ืš ืืช ื—ืœื•ืŸ ื”ื–ืžืŸ ืขืœื™ื• ืื ื™ ืžืกืชื›ืœ. ื‘ืžืงื•ื ืœื”ืกืชื›ืœ ืขืœ ื”ื“ื‘ืจ ืฉืื ื™ ืฆืจื™ืš ืœืœืžื•ื“ ืขื›ืฉื™ื• ืื ื™ ืืกืชื›ืœ ืื—ื•ืจื” ื•ืืฉืืœ- 1. ื›ืžื” ื˜ื›ื ื•ืœื•ื’ื™ื•ืช ื—ื“ืฉื•ืช ืœืžื“ืชื™ ื‘ืฉื ื” ื”ืื—ืจื•ื ื”? 2. ื›ืžื” ื›ืœื™ื ื—ื“ืฉื™ื ืฉื™ืœื‘ืชื™ ื‘ืขื‘ื•ื“ื” ืฉืœื™ ื‘ืฉื ื” ื”ืื—ืจื•ื ื” ื‘ืฆื•ืจื” ืฉืชืจืžื” ืœืคืจื•ื“ื•ืงื˜ื™ื‘ื™ื•ืช? 3. ื”ืื ื™ืฉ ืœื™ ืจืฉื™ืžืช ื˜ื›ื ื•ืœื•ื’ื™ื•ืช ืœืœื™ืžื•ื“ ืžืขื•ืœื ื”ืชื•ื›ืŸ ืฉืœื™ ืฉืื ื™ ื™ื•ื“ืข ืฉืื ื™ ืฆืจื™ืš ืœื—ืงื•ืจ? ื•ืื ื›ืŸ ื”ืื ื”ืฆืœื—ืชื™ ืœืงืฆืจ ืื•ืชื” ื‘ืฉื ื” ื”ืื—ืจื•ื ื”? ื›ืฉืžืกืชื›ืœื™ื ืขืœ ืฉื ื” ืื—ื•ืจื” ื‘ืžืงื•ื ืขืœ ืžื—ืจ ื‘ื‘ื•ืงืจ ื™ื•ืชืจ ืงืœ ืœื”ื‘ื™ืŸ ืืช ื”ืกื™ื˜ื•ืืฆื™ื”. ื›ืžื” ืžื•ืฆื“ืงื•ืช ืฉืœื ื™ื”ื™ื• ื”ืกื™ื‘ื•ืช ืฉื™ืฉ ืœื™ ื”ื™ื•ื ื”ืŸ ื‘ื˜ื— ืœื ื”ื™ื• ืฉื ืœืคื ื™ ื—ื•ื“ืฉ, ื—ื•ื“ืฉื™ื™ื ืื• ื—ืฆื™ ืฉื ื”. ื™ื•ืชืจ ืžื–ื”, ืจืง ืœืฉื™ื ืœื‘ ืฉื‘ืฉื ื” ื”ืื—ืจื•ื ื” ืœื ืœืงื—ืช ืืฃ ืฆืขื“ ืงื“ื™ืžื” ื–ื” ื—ื•ื•ื™ื” ืžื˜ืœื˜ืœืช ืฉื™ื›ื•ืœื” ืœืฉื ื•ืช ืกื“ืจื™ ืขื“ื™ืคื•ื™ื•ืช. ื™ืฉ ืœืžื•ื— ืฉืœื ื• ื™ื›ื•ืœืช ืžื•ืคืœืื” ืœื”ืขื‘ื™ืจ ืฉื ื™ื ืขืœ ื˜ื™ื™ืก ืื•ื˜ื•ืžื˜ื™. ื–ื™ื”ื•ื™ ื”ืžื ื’ื ื•ืŸ ื”ื–ื” ื‘ื–ืžืŸ ื”ื•ื ื”ื”ื–ื“ืžื ื•ืช ืฉืœื ื• ืœื—ื™ื™ื ืฉืžื—ื™ื ื™ื•ืชืจ.

ToCode
1 420
ืžืฉื—ืงื™ื ืขื ืžืงื‘ื™ืœื™ื•ืช ื‘ืกืงืืœื” (ื—ืœืง 2) ื‘ื—ืœืง ื”ืงื•ื“ื ืฉืœ ื”ืคื•ืกื˜ ื›ืชื‘ืชื™ ืขืœ pmap ื•ืื™ืš ืืคืฉืจ ืœื”ืฉืชืžืฉ ื‘ื• ื›ื“ื™ ืœื—ืœืง ืคืขื•ืœื” ื—ื™ืฉื•ื‘ื™ืช ืœืžืกืคืจ ืชื”ืœื™ื›ื•ื ื™ื ื›ื“ื™ ืœืฉืคืจ ื‘ื™ืฆื•ืขื™ื. ื”ื™ื•ื ืื ื™ ืจื•ืฆื” ืœื“ื‘ืจ ืขืœ ืขื‘ื•ื“ืช IO, ืขืœ ื”ืžื’ื‘ืœื” ืฉืœ Thread Pool ื‘ืžื™ืงื‘ื•ืœ ืžืฉื™ืžื•ืช ื”ืงืฉื•ืจื•ืช ืœ IO ื•ืขืœ ื”ืคื™ืชืจื•ืŸ ืขื Virtual Threads. ืžื” ื‘ืขืฆื ื”ื‘ืขื™ื” ื ืชื—ื™ืœ ืขื ื”ืงื•ื“ ื”ื‘ื ื‘ืกืงืืœื” ืฉืžืฉืชืžืฉ ื‘ Thread Pool ื›ื“ื™ ืœื”ื•ืจื™ื“ ื‘ืžืงื‘ื™ืœ ืžื™ื“ืข ืž 50 ืขืžื•ื“ื™ื ื‘ืืชืจ ืžืกื•ื™ื (ื›ืŸ ื”ื ืชื•ื ื™ื ื‘ืืชืจ ืžื–ื•ื™ืคื™ื ืื‘ืœ ื–ื” ืœื ืžืฉื ื”):
object futures {
  given ExecutionContext = ExecutionContext.global

  private def printUrlContent(url: String): Unit =
    Using(Source.fromURL(url)) { reader =>
      reader.getLines().mkString("\n")
    }
    println(s"Done: ${url}")


  @main
  def test(): Unit =
    val s1 = System.nanoTime()
    1.to(50)
      .map {i => s"https://dummyjson.com/products/${i}" }
      .map { url => Future { printUrlContent(url)} }
      .foreach { f => Await.result(f, Duration.Inf) }

    val s2 = System.nanoTime()
    println(s"Took ${s2 - s1} ns")

}

ืื– ื‘ื’ื“ื•ืœ ืื ื—ื ื• ืžื—ืฉื‘ื™ื 50 ื›ืชื•ื‘ื•ืช ืื™ื ื˜ืจื ื˜ ืžืืชืจ dummyjson.com, ืฉื•ืœื—ื™ื ื‘ืงืฉืช HTTP ืœื›ืœ ื›ืชื•ื‘ืช ื•ื‘ื•ื“ืงื™ื ื›ืžื” ื–ืžืŸ ืœืงื— ืœืžืฉื•ืš ืืช ื›ืœ ื”ืžื™ื“ืข. ื”ืจืฆื” ืฉืœ ื”ืชื•ื›ื ื™ืช ืžืฆื™ื’ื” ืชื•ืฆืื” ืžืขื ื™ื™ื ืช - ืื ื—ื ื• ืจื•ืื™ื ืืช ื”ืคืœื˜ ื ื›ืชื‘ ืœืžืกืš ื‘ืงื‘ื•ืฆื•ืช ืฉืœ URL-ื™ื, ื›ืœื•ืžืจ ืžื—ื›ื™ื ืงืฆืช ื–ืžืŸ, ืจื•ืื™ื ื”ื“ืคืกื” ืฉืœ ืžืกืคืจ ืฉื•ืจื•ืช ื•ืื– ืžื—ื›ื™ื ืขื•ื“ ืงืฆืช ื•ืขื•ื“ ื”ื“ืคืกื”. ื–ื” ืงื•ืจื” ื‘ื’ืœืœ ื”ืžื‘ื ื” ืฉืœ Thread Pool ื•ื”ืฉื™ืœื•ื‘ ืขื ืขื‘ื•ื“ืช IO. ื‘ืกื•ื’ ืขื‘ื•ื“ื” ื›ื–ื” ืžื” ืฉื—ื•ืกื ืื•ืชื ื• ื”ื•ื ื”ืจืฉืช ื•ืœื ื”ืžื—ืฉื‘ ืฉืœื ื•, ื•ืœื›ืŸ ื›ืœ ื”ืชื”ืœื™ื›ื•ื ื™ื ืขื•ื‘ื“ื™ื ืขืœ ื ื™ื•ื˜ืจืœ ื•ื‘ืขืฆื ืžื—ื›ื™ื ืœืžื™ื“ืข. ื”ื‘ืขื™ื” ืฉื” Thread Pool ืžื•ื›ืŸ ืœื”ืจื™ืฅ ืจืง ืžืกืคืจ ืžื•ื’ื‘ืœ ืฉืœ ืชื”ืœื™ื›ื•ื ื™ื ื•ืœื›ืŸ ืฆืจื™ืš ืœื—ื›ื•ืช ืขื“ ืฉืชื”ืœื™ื›ื•ืŸ ื™ืกื™ื™ื ื•ื™ืชืคื ื” ืœืคื ื™ ืฉืžืชื—ื™ืœื™ื ืœื”ื•ืจื™ื“ ืืช ื”ื ืชื™ื‘ ื”ื‘ื. ืžืขื‘ืจ ืœ Virtual Threads ื•ื›ืืŸ ืื ื—ื ื• ืžื’ืœื™ื ืืช ื”ืคื•ื˜ื ืฆื™ืืœ ืฉืœ Virtual Threads. ื‘ื“ืจืš ื›ืœืœ ื›ืœ Thread ืชื•ืคืก ืžืฉืื‘ื™ื ื•ืœื›ืŸ ืœื ืžื•ืžืœืฅ ืœื™ืฆื•ืจ ื™ื•ืชืจ ืžื“ื™ ืžื”ื, ื‘ืฉืœื‘ ืžืกื•ื™ื ื”ื ื™ืฆืจื• ืขื•ืžืก ืขืœ ืžืขืจื›ืช ื”ื”ืคืขืœื” ื•ืจืง ื™ืื˜ื• ืืช ื”ืชื•ื›ื ื™ืช. ืชื”ืœื™ื›ื•ืŸ ื•ื™ืจื˜ื•ืืœื™ ื”ื•ื ืžื ื’ื ื•ืŸ ืฉืœ ื” JVM ืฉืœื ื™ื•ืฆืจ Thread ื‘ืžืขืจื›ืช ื”ื”ืคืขืœื” (ื–ื” ื ืงืจื fiber ื‘ื”ืจื‘ื” ืžืงื•ืžื•ืช ืื—ืจื™ื) ื•ืœื›ืŸ ืืคืฉืจ ืœื™ืฆื•ืจ ื”ืžื•ืŸ ืžืžื ื•. ื ื›ื•ืŸ ืื ื”ืคืขื•ืœื” ืฉืื ื—ื ื• ืžื ืกื™ื ืœืขืฉื•ืช ื”ื™ื ืžืฉื™ืžื” ื—ื™ืฉื•ื‘ื™ืช ืœื”ื•ืกื™ืฃ ืขื•ื“ ืชื”ืœื™ื›ื•ื ื™ื ืื• ืชื”ืœื™ื›ื•ื ื™ื ื•ื™ืจื˜ื•ืืœื™ื™ื ืœื ื™ืฉืคืจ ืืช ืžืฆื‘ื ื•, ื›ื™ ืขื“ื™ื™ืŸ ื™ื”ื™ื” ืขื•ืžืก ืขืœ ื”ืžืขื‘ื“, ืื‘ืœ ื›ืฉืžื“ื•ื‘ืจ ื‘ืคืขื•ืœื•ืช IO ืžืžื™ืœื ื”ืžืขื‘ื“ ืœื ืขื•ืฉื” ื›ืœื•ื ื•ื”ืื™ื˜ื™ื•ืช ืžื’ื™ืขื” ืžื”ืจืฉืช ื•ืœื ืžื”ืžื—ืฉื‘ ืฉืœื ื• - ื•ืœื›ืŸ ืชื”ืœื™ื›ื•ื ื™ื ื•ื™ืจื˜ื•ืืœื™ื™ื ื™ื›ื•ืœื™ื ืœืฉื ื•ืช ืืช ื”ืชืžื•ื ื”. ื‘ืกืงืืœื” (ื•ื’ื ื‘ Java) ื™ืฉ ืงืœืืก ื‘ืฉื ExecutorService ืฉืื—ืจืื™ ืขืœ ื™ืฆื™ืจืช ื”ืชื”ืœื™ื›ื•ื ื™ื ื•ืœื›ืŸ ื›ืœ ืžื” ืฉืฆืจื™ืš ื‘ืฉื‘ื™ืœ ืœื”ืชื—ื™ืœ ืœืขื‘ื•ื“ ืขื ืชื”ืœื™ื›ื•ื ื™ื ื•ื™ืจื˜ื•ืืœื™ื™ื ื”ื•ื ืœืฉื ื•ืช ืืช ื” ExecutorService ืฉืœื ื•. ืขื“ื›ื•ืŸ ื”ืชื•ื›ื ื™ืช ืœืขื‘ื•ื“ื” ืขื ืชื”ืœื™ื›ื•ื ื™ื ื•ื™ืจื˜ื•ืืœื™ื™ื ื”ื•ื ื‘ืกืš ื”ื›ืœ ืฉื™ื ื•ื™ ืฉืœ ื”ืฉื•ืจื” ื”ืจืืฉื•ื ื” ืœ:
given ExecutionContext = ExecutionContext.fromExecutorService(Executors.newVirtualThreadPerTaskExecutor())
ื•ื”ืชื•ื›ื ื™ืช ื”ืžืœืื”:
object futures {
  given ExecutionContext = ExecutionContext.fromExecutorService(Executors.newVirtualThreadPerTaskExecutor())
//  given ExecutionContext = ExecutionContext.global

  private def printUrlContent(url: String): Unit =
    Using(Source.fromURL(url)) { reader =>
      reader.getLines().mkString("\n")
    }
    println(s"Done: ${url}")


  @main
  def test(): Unit =
    val s1 = System.nanoTime()
    1.to(50)
      .map {i => s"https://dummyjson.com/products/${i}" }
      .map { url => Future { printUrlContent(url)} }
      .foreach { f => Await.result(f, Duration.Inf) }

    val s2 = System.nanoTime()
    println(s"Took ${s2 - s1} ns")

}

ื’ื™ืจืกื” ื–ื• ืฉืœ ื”ืชื•ื›ื ื™ืช ืจืฆื” ื‘ืžื—ืฆื™ืช ื”ื–ืžืŸ, ื•ืžื” ืฉื™ื•ืชืจ ืžืขื ื™ื™ืŸ ื”ื•ื ืฉืื™ืŸ ื‘ื” ืืช ื”ื—ืœื•ืงื” ืœืงื‘ื•ืฆื•ืช ืฉืืคื™ื™ื ื” ืืช ื”ืขื‘ื•ื“ื” ืขื Thread Pool. ื›ืœ ื”ื”ื•ื“ืขื•ืช ื ื›ืชื‘ื•ืช ืœืžืกืš ื™ื—ื“, ื‘ื’ืœืœ ืฉืžืจืืฉ ื™ืฆืจื ื• Thread ื•ื™ืจื˜ื•ืืœื™ ืœื›ืœ ืžืฉื™ืžื”.

ToCode
1 420
ื‘ื™ื™ ื‘ื™ื™ map ื‘ืฉื‘ื™ืœ ืœืฉื ื•ืช ืขืจื›ื™ื ื‘ืžื™ืงื•ื ืžืกื•ื™ื ื‘ JavaScript ืื ืื™ ืคืขื ืฉืžืจืชื ืžืขืจืš ื‘ืกื˜ื™ื™ื˜ ืฉืœ ืงื•ืžืคื•ื ื ื˜ืช ืจื™ืืงื˜ ืืชื ื•ื•ื“ืื™ ื–ื•ื›ืจื™ื ืืช ื”ืจื’ืข ืฉื ื™ืกื™ืชื ืœืฉื ื•ืช ืจืง ืขืจืš ืื—ื“ ื‘ืžืขืจืš ื•ืœื”ืขื‘ื™ืจ ืืช ื”ืชื•ืฆืื” ืœ set, ืจืง ื‘ืฉื‘ื™ืœ ืœื’ืœื•ืช ืฉ setState ืœื ืขื•ืฉื” ื›ืœื•ื ื›ื™ ื”ืžืขืจืš ืขืฆืžื• ืœื ื”ืฉืชื ื”. ืื—ืจื™ ื–ื” ืœืžื“ืชื ืœื”ืฉืชืžืฉ ื‘ map ื›ื“ื™ ืœื™ืฆื•ืจ ืžืขืจืš ื—ื“ืฉ ืขื ืฉื™ื ื•ื™ ืืœืžื ื˜ ื‘ืื™ื ื“ืงืก ืžืกื•ื™ื-
const newItems = oldItems.map((item, index) => 
    index === 1 ? 99 : item);
ื•ืื– ื”ื’ื™ืขื” immer ื•ืฉื•ื‘ ื”ืฆืœื—ื ื• ืœื›ืชื•ื‘ ืงื•ื“ ืจื’ื™ืœ ืื‘ืœ ื™ื“ืขื ื• ื‘ืœื‘ ืฉื–ื” ืœื ื‘ื“ื™ื•ืง ื–ื” ื•ืฉืžื ื’ื ื•ืŸ ื”ืคืจื•ืงืกื™ื ืฉืœ immer ืขื•ื‘ื“ ืื•ืžื ื ื‘ืจื•ื‘ ื”ืžืงืจื™ื ืื‘ืœ ื‘ืกื•ืฃ ืชืžื™ื“ ืžื—ื›ื” ืื™ื–ื” ื‘ืื’ (ืœื ื‘ื’ืœืœ immer ื‘ืจื•ืจ, ืืชื ืคืฉื•ื˜ ืžื—ื–ื™ืงื™ื ืืช ื–ื” ืœื ื ื›ื•ืŸ). ื‘ืงื™ืฆื•ืจ ืงื™ื˜ื•ืจื™ื ื‘ืฆื“ ืœืื—ืจื•ื ื” JavaScript ืงื™ื‘ืœื” ื‘ื›ืœ ื”ื“ืคื“ืคื ื™ื ืชืžื™ื›ื” ื‘ืคื™ืชืจื•ืŸ ืžื•ื‘ื ื” ืœืฉื™ื ื•ื™ ืžืขืจื›ื™ื ืœืคื™ ืื™ื ื“ืงืก ื•ื‘ืœื™ map. ื–ื” ื ืจืื” ื›ื›ื”-
const newItems = oldItems.with(1, 99);
ื ืฉื™ื ืœื‘ ืฉืื™ ืืคืฉืจ ืœื›ืชื•ื‘ ืื—ืจื™ ืกื•ืฃ ื”ืžืขืจืš ื›ืš ืฉื–ื” ื ื›ืฉืœ:
[].with(99, 0)
ื‘ื ื•ืกืฃ with ืฉื•ื‘ืจ ืžืขืจื›ื™ื ืžืจื•ื•ื—ื™ื, ืื‘ืœ ืื ื™ ืœื ื‘ื˜ื•ื— ื›ืžื” ื ื–ืง ื–ื” ืขืœื•ืœ ืœื’ืจื•ื. ื›ืœื•ืžืจ ื”ืงื•ื“ ื”ื–ื”:
Array(10).forEach(() => console.log('1'))
ื•ื”ืงื•ื“ ื”ื–ื”:
Array(10).with(0, 0).forEach(() => console.log('1'))
ื™ืขืฉื• ื“ื‘ืจื™ื ืฉื•ื ื™ื - ื”ืจืืฉื•ืŸ ืœื ื™ื“ืคื™ืก ื›ืœื•ื, ื”ืฉื ื™ ื™ื“ืคื™ืก 10 ืคืขืžื™ื ืืช ื”ื”ื•ื“ืขื”. ืื™ืŸ ืชืžื™ื›ื” ื‘ืžืกืคืจ ืื™ื ื“ืงืกื™ื ืœื›ืชื™ื‘ื” ืœืชื•ืš ืžืขืจื›ื™ื ืžืงื•ื ื ื™ื, ืื‘ืœ ื›ืŸ ื™ืฉ ืชืžื™ื›ื” ื‘ืื™ื ื“ืงืกื™ื ืฉืœื™ืœื™ื™ื ืœื›ืชื™ื‘ื” ืžืกื•ืฃ ื”ืžืขืจืš:
[1, 2, 3, 4, 5].with(-1, 10)

ToCode
1 420
ื”ื™ื•ื ืœืžื“ืชื™ - ืื™ืคื•ืก ื”ื’ื“ืจื•ืช postcss ื‘ืคืจื•ื™ืงื˜ vite ืœืคืขืžื™ื ืงืฉื” ืœื”ื‘ื™ืŸ ืœืžื” ืคืจื•ื™ืงื˜ื™ Front End ืœื ืžืฆืœื™ื—ื™ื ืœืขื‘ื•ื“ ื˜ื•ื‘ ื™ื—ื“, ืื• ืฉืื•ืœื™ ื”ื‘ืขื™ื” ื”ื™ื ืืฆืœื ื• ื”ืžืชื›ื ืชื™ื ืฉืคืฉื•ื˜ ื“ื•ื—ืคื™ื ืขื•ื“ ื•ืขื•ื“ ืฉื˜ื•ื™ื•ืช ืœืคืจื•ื™ืงื˜ ื•ื‘ืกื•ืฃ ืžืชืคืœืื™ื ื›ืฉืžื•ืคื™ืขื•ืช ื”ื•ื“ืขื•ืช ืฉื’ื™ืื” ืžื•ื–ืจื•ืช. ื”ืกื™ืคื•ืจ ืฉื”ื™ื•ื ืœืงื— ืœื™ ื™ื•ืชืจ ืžื“ื™ ืฉืขื•ืช ืžื”ื—ื™ื™ื ืงืฉื•ืจ ืœ postcss ื•ืœื”ืชื ื”ื’ื•ืช ื”ืžื•ื–ืจื” ืฉืœื• ื‘ืชื•ืš ืคืจื•ื™ืงื˜ vite - ื‘ื”ืขื“ืจ ื”ื’ื“ืจื” ืื—ืจืช, postcss ื™ื—ืคืฉ ืงื•ื‘ืฅ ื”ื’ื“ืจื•ืช ื‘ืžืขืœื” ืขืฅ ื”ืชื™ืงื™ื•ืช ืขื“ ืœืชื™ืงื™ื™ืช ื”ื‘ื™ืช. ื‘ืฉื‘ื™ืœ ื”ื ื™ืกื•ื™ ืฉืžืชื™ ื‘ืชื™ืงื™ื™ืช ื”ื‘ื™ืช ืงื•ื‘ืฅ ื‘ืฉื postcss.config.js ืขื ื”ืชื•ื›ืŸ ื”ื‘ื:
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
};
ื•ืื– ื™ืฆืจืชื™ ืคืจื•ื™ืงื˜ vite ื—ื“ืฉ ืœื’ืžืจื™ ื‘ืชื™ืงื™ื™ื”:
/Users/ynonp/a/b/c/d/helloworld
ื”ืคืขืœืชื™ npm run build ื‘ืชื™ืงื™ื” ื•ืงื™ื‘ืœืชื™ ืืช ื”ื•ื“ืขืช ื”ืฉื’ื™ืื” ื”ื‘ืื”:
> helloworld@0.0.0 build
> tsc && vite build

vite v5.1.3 building for production...
transforming (1) index.htmlnode:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Failed to load PostCSS config: Failed to load PostCSS config (searchPath: /Users/ynonp/a/b/c/d/helloworld): [Error] Loading PostCSS Plugin failed: Cannot find module 'tailwindcss'
Require stack:
- /Users/ynonp/postcss.config.js

(@/Users/ynonp/postcss.config.js)
Error: Loading PostCSS Plugin failed: Cannot find module 'tailwindcss'
Require stack:
- /Users/ynonp/postcss.config.js

(@/Users/ynonp/postcss.config.js)
    at load (file:///Users/ynonp/a/b/c/d/helloworld/node_modules/vite/dist/node/chunks/dep-stQc5rCc.js:28883:11)
    at file:///Users/ynonp/a/b/c/d/helloworld/node_modules/vite/dist/node/chunks/dep-stQc5rCc.js:28908:16
    at Array.map (<anonymous>)
    at plugins (file:///Users/ynonp/a/b/c/d/helloworld/node_modules/vite/dist/node/chunks/dep-stQc5rCc.js:28907:8)
    at processResult (file:///Users/ynonp/a/b/c/d/helloworld/node_modules/vite/dist/node/chunks/dep-stQc5rCc.js:28977:14)
    at file:///Users/ynonp/a/b/c/d/helloworld/node_modules/vite/dist/node/chunks/dep-stQc5rCc.js:29107:14]

Node.js v21.5.0
ื•ื›ืŸ ื–ื” ืœืงื— ื”ืจื‘ื” ื™ื•ืชืจ ื–ืžืŸ ืœื’ืœื•ืช ืฉื”ืกื™ื‘ื” ืœื”ื•ื“ืขื” ื”ื™ื ื‘ืขืฆื ื”ืงื•ื‘ืฅ postcss.config.js ืฉื ืžืฆื ื‘ืชื™ืงื™ื™ืช ื”ื‘ื™ืช ืฉืœื™. ืคื™ืชืจื•ืŸ? ื“ื™ ืคืฉื•ื˜ ืžืกืชื‘ืจ ืื—ืจื™ ืฉืžื‘ื™ื ื™ื ืืช ื”ื‘ืขื™ื”. ื™ื•ืฆืจื™ื ืงื•ื‘ืฅ vite.config.js ื‘ืชื™ืงื™ื™ืช ื”ืคืจื•ื™ืงื˜ ืขื ื”ืชื•ื›ืŸ ื”ื‘ื ื•ื”ื›ืœ ืžืกืชื“ืจ:
import { defineConfig } from 'vite'

// https://vitejs.dev/config/
export default defineConfig({
  css: {
    postcss: {},
  },
})
ืื– ื ื›ื•ืŸ ืื ื™ ืœื ืืงื‘ืœ ืืช ื”ื—ืฆื™ ื™ื•ื ืฉืœื™ ื‘ื—ื–ืจื”, ืื‘ืœ ืื•ืœื™ ื”ืคื•ืกื˜ ื”ื–ื” ื™ื—ืกื•ืš ืœื›ื ื›ืžื” ืฉืขื•ืช.

ToCode
1 420
ืขื•ื“ ืžื—ืฉื‘ื” ืขืœ ืชื‘ื ื™ืช ื” index.ts ืฉืžื™ื™ืฆื ื”ื›ืœ ื‘ื•ืื• ื ื“ืžื™ื™ืŸ ืคืจื•ื™ืงื˜ ืจื™ืืงื˜ ืฉื™ืฉ ื‘ื• ืชื™ืงื™ื™ื” ื‘ืฉื src/components/HomePage ื•ื‘ืชื•ื›ื” ืขืจื™ืžื” ืฉืœ ืชื™ืงื™ื•ืช ื•ืงื•ื‘ืฅ ืื—ื“ ื‘ืฉื index.ts:
.
โ”œโ”€โ”€ EmptyState
โ”‚   โ”œโ”€โ”€ EmptyState.tsx
โ”‚   โ””โ”€โ”€ index.ts
โ”œโ”€โ”€ ErrorState
โ”‚   โ”œโ”€โ”€ ErrorState.tsx
โ”‚   โ”œโ”€โ”€ ErrorState.types.ts
โ”‚   โ””โ”€โ”€ index.ts
โ”œโ”€โ”€ RecentArticles
โ”‚   โ”œโ”€โ”€ RecentArticles.tsx
โ”‚   โ”œโ”€โ”€ RecentArticles.types.ts
โ”‚   โ””โ”€โ”€ index.ts
โ”œโ”€โ”€ RecentArticlesCard
โ”‚   โ”œโ”€โ”€ RecentArticleCard.tsx
โ”‚   โ”œโ”€โ”€ RecentArticleCard.types.ts
โ”‚   โ””โ”€โ”€ index.ts
โ”œโ”€โ”€ RecentArticlesContent
โ”‚   โ”œโ”€โ”€ RecentArticlesContent.tsx
โ”‚   โ”œโ”€โ”€ RecentArticlesContent.types.ts
โ”‚   โ””โ”€โ”€ index.ts
โ””โ”€โ”€ index.ts
ืชื•ื›ืŸ ื”ืงื•ื‘ืฅ index.ts ื™ื”ื™ื”:
export * from './EmptyState';
export * from './ErrorState';
export * from './RecentArticles';
export * from './RecentArticlesCard';
export * from './RecentArticlesContent';
ืœืžื” ืฉืžื™ืฉื”ื• ื™ื›ืชื•ื‘ ื›ื›ื”? ืžื” ื”ื™ืชืจื•ื ื•ืช ื•ืžื” ื”ื—ืกืจื•ื ื•ืช? ื•ื”ืื ื›ื“ืื™ ืœื ื• ื’ื ืœื”ืฉืชืžืฉ ื‘ืชื‘ื ื™ืช ื–ื• ื‘ืคืจื•ื™ืงื˜ื™ื ืฉืœื ื•? (ื›ืŸ ืื ื™ ื™ื•ื“ืข ืจื•ื‘ื›ื ื›ื‘ืจ ืžืฉืชืžืฉื™ื. ื‘ื’ืœืœ ื–ื” ื”ืคื•ืกื˜) ืœืžื” ื›ืŸ ืœื›ืชื•ื‘ ื›ื›ื” ื”ืฉื™ืžื•ืฉ ื‘ืงื•ื‘ืฅ ืื™ื ื“ืงืก ืจืืฉื™ ื‘ืชื™ืงื™ื” ื ื•ืขื“ ืœื”ืงืœ ืขืœ ืื ืฉื™ื ืฉืขื•ืฉื™ื import ืœืงื‘ืฆื™ื ืžืื•ืชื” ืชื™ืงื™ื™ื”. ืงื•ื‘ืฅ ืื—ืจ ืžืื•ืชื• ื”ืคืจื•ื™ืงื˜ ืฉืžื™ื™ื‘ื ืงื‘ืฆื™ื ื™ื•ื›ืœ ืœื›ืชื•ื‘:
import { EmptyState, ErrorState, RecentArticles } from '@/components';
ื•ื–ื” ื ื—ืžื“ ื›ื™ ืขื›ืฉื™ื• ืœื ืฆืจื™ืš ืœื—ืฉื•ื‘ ืžืื™ื–ื• ืชื™ืงื™ื™ื” ื”ื’ื™ืขื” ื›ืœ ืงื•ืžืคื•ื ื ื˜ื”. ื™ื•ืชืจ ืžื–ื”, ืื ื”ืคืจื•ื™ืงื˜ ืฉืœื™ ื”ื™ื” ืกืคืจื™ื” ืฉืื ืฉื™ื ืื—ืจื™ื ืขื•ืฉื™ื import ืœื“ื‘ืจื™ื ืžืชื•ื›ื”, ืื– ื”ื™ื™ืชื™ ื™ื›ื•ืœ ืœื”ืขืœื•ืช ื’ื™ืจืกื” ื•ืœืฉื ื•ืช ืžื™ืงื•ืžื™ื ืฉืœ ืงื‘ืฆื™ื ื•ืฉืžื•ืช ืฉืœื”ื ื‘ืœื™ ืฉืื•ืชื ืื ืฉื™ื ืฉืžืฉืชืžืฉื™ื ื‘ืกืคืจื™ื” ืฉืœื™ ื™ืฆื˜ืจื›ื• ืœืขื“ื›ืŸ ืืช ื”ืงื•ื“ ืฉืœื”ื. ื–ื” ื›ื‘ืจ ื ื™ืฆื—ื•ืŸ ืจืฆื™ื ื™. ืœืžื” ืœื ืœื›ืชื•ื‘ ื›ื›ื” ื‘ื—ื–ืจื” ืœืฉื•ืจืช ื” import ืฉื”ืฆื’ืชื™ ื‘ืงื˜ืข ื”ืงื•ื“ื-
import { EmptyState, ErrorState, RecentArticles } from '@/components';
ืžื™ ืฉืงื•ืจื ืืช ื–ื” ืฆืจื™ืš ืœื”ื›ื™ืจ ืœืขื•ืžืง ืืช ืžื‘ื ื” ื”ืชื™ืงื™ื•ืช ื‘ืคืจื•ื™ืงื˜ (ื•ืœื–ื›ื•ืจ ืืช ื”ืžื‘ื ื” ื‘ืขืœ ืคื”), ืื• ืœืกืžื•ืš ืขืœ IDE ืฉื™ื“ืข ืœืงืจื•ื ืื™ืคื” ื›ืœ ื“ื‘ืจ. ืœืคืขืžื™ื ื™ืฉ ืœื ื• ื’ื™ืฉื” ืœื›ื–ื” IDE ืื‘ืœ ืœืคืขืžื™ื ืื ื—ื ื• ืฆืจื™ื›ื™ื ืœืงืจื•ื ืงื•ื“ ื‘ืกื‘ื™ื‘ื” ืคื—ื•ืช ื™ื“ื™ื“ื•ืชื™ืช ื•ืื– ื™ื•ืชืจ ืงืฉื” ืœืžืฆื•ื ืืช ื”ืงื•ืžืคื•ื ื ื˜ื•ืช. ื™ื•ืชืจ ื’ืจื•ืข, ืงื‘ืฆื™ index.ts ื“ื•ืจืฉื™ื ืชื—ื–ื•ืงื” - ื›ืœ ืคืขื ืฉืื ื™ ืžืฉื ื” ืฉื ืฉืœ ืžืฉื”ื• ื‘ืคืจื•ื™ืงื˜ ืื• ืžื–ื™ื– ืงื•ื‘ืฅ ืžืžืงื•ื ืœืžืงื•ื ืื ื™ ืฆืจื™ืš ืœืชืงืŸ ืืช ื”ื”ืคื ื™ื•ืช ื‘ืงื•ื‘ืฅ ื”ืื™ื ื“ืงืก ื”ืžืชืื™ื. ืื ื”ืคืจื•ื™ืงื˜ ื”ื•ื ืกืคืจื™ื” ืขื ืžืฉืชืžืฉื™ื ื—ื™ืฆื•ื ื™ื™ื ื–ื” ืœื’ืžืจื™ ืฉื•ื•ื” ืืช ื”ื”ืฉืงืขื”, ืื‘ืœ ืื ื”ืžืฉืชืžืฉ ื”ื™ื—ื™ื“ ื‘ืงื•ืžืคื•ื ื ื˜ื•ืช ื”ื•ื ืงื•ื“ ื”ืคืจื•ื™ืงื˜ ืขืฆืžื• ืื– ืœื ื”ืจื•ื•ื—ื ื• ื›ืœื•ื.

ToCode
1 420
8. ืžืขื›ืฉื™ื• ื›ืœ ืฉื™ื ื•ื™ ืฉืชืขืฉื• ื‘ืขื ืฃ gh-pages ื•ืชื“ื—ืคื• ืœื’ื™ื˜ื”ืื‘ ื™ื’ืจื•ื ืœื‘ื ื™ื™ื” ืžื—ื“ืฉ ืฉืœ ื“ืฃ ื”ืคืจื•ื™ืงื˜.

ToCode
1 420
ืื™ืš ืœื™ืฆื•ืจ ื“ืฃ Github Pages ืœืคืจื•ื™ืงื˜ ืฉืœืš ื‘ื™ืŸ ืื ืืชื ื‘ื•ื ื™ื ืคืจื•ื™ืงื˜ ื‘ืฉื‘ื™ืœ ื”ืขื•ืœื ืื• ืจืง ื‘ืฉื‘ื™ืœ ืงื•ืจื•ืช ื”ื—ื™ื™ื, ื“ืฃ ื•ื•ื‘ ืœืคืจื•ื™ืงื˜ ื”ื–ื” ืฉืžืกื‘ื™ืจ ืžื” ื”ื•ื ืขื•ืฉื” ื™ื›ื•ืœ ืœืขื–ื•ืจ ืœืื ืฉื™ื ืœืžืฆื•ื ืืชื›ื, ืื• ืœื‘ื•ืกื™ื ืคื•ื˜ื ืฆื™ืืœื™ื™ื ืœื”ืชืจืฉื ืžื”ืขื‘ื•ื“ื” ืฉืœื›ื. ื•ืื ื›ื‘ืจ ื”ืคืจื•ื™ืงื˜ ืฉืžื•ืจ ืขืœ ื’ื™ื˜ื”ืื‘ ื‘ื•ืื• ื ื‘ื ื” ืœื• ื’ื ื“ืฃ ืžื™ื“ืข ืฉื™ืื•ื—ืกืŸ ื‘ืื•ืชื• ืžืงื•ื, ื‘ืชืฉืชื™ืช ืฉืœ Github Pages. ืื™ืš ืœื™ืฆื•ืจ ื“ืฃ Github Pages ืœืคืจื•ื™ืงื˜ ืื—ืจื™ ืฉื”ืขืœื™ืชื ืืช ื”ืคืจื•ื™ืงื˜ ืœื’ื™ื˜ื”ืื‘ ื”ื’ื™ืข ื”ื–ืžืŸ ืœื™ืฆื•ืจ ืขื‘ื•ืจื• ื“ืฃ ืžื™ื“ืข. ื”ื“ืฃ ื”ื•ื ืคืจื•ื™ืงื˜ Front End ืจื’ื™ืœ ืฉื ืฉืžืจ ื‘ืชื™ืงื™ื™ื” ื ืคืจื“ืช ื‘ืคืจื•ื™ืงื˜, ื‘ื“ื•ื’ืžื” ืฉืœื™ ืื ื™ ืงื•ืจื ืœืชื™ืงื™ื” gh-pages. ืื ื™ ืžื ื”ืœ ืืช ื”ืงื‘ืฆื™ื ื‘ื“ืฃ ื”ืžื™ื“ืข ื‘ืขื ืฃ ื ืคืจื“, ืฉื’ื ืœื• ืื ื™ ืงื•ืจื ื‘ืฉื‘ื™ืœ ื”ื ื•ื—ื•ืช gh-pages. ื›ืœ ืคืขื ืฉื ืขืœื” ืฉื™ื ื•ื™ ืœืื•ืชื• ืขื ืฃ ื‘ืื•ืคืŸ ืื•ื˜ื•ืžื˜ื™ ื’ื™ื˜ื”ืื‘ ื™ื‘ื ื” ืืช ื“ืฃ ื”ืžื™ื“ืข ื•ื™ืขื“ื›ืŸ ืื•ืชื• ื‘ืจืฉืช. ื”ื›ืชื•ื‘ืช ืฉืœ ื“ืฃ ื”ืžื™ื“ืข ืชื”ื™ื”:
https://<user>.github.io/<repo>
ื›ืืฉืจ user ื”ื•ื ืฉื ื”ืžืฉืชืžืฉ ื‘ื’ื™ื˜ื”ืื‘ ืฉืœื›ื ื• repo ื”ื•ื ืฉื ื”ืžืื’ืจ ืฉืœ ื”ืคืจื•ื™ืงื˜. ืžื•ื›ื ื™ื? ื‘ื•ืื• ื ื™ื›ื ืก ืœืชื™ืงื™ื™ืช ื”ืคืจื•ื™ืงื˜ ื•ื ืฆื ืœื“ืจืš- 1. ืฆืจื• ืืช ื”ืขื ืฃ gh-pages ื‘ื• ื™ื™ืฉืžืจ ื”ื“ืฃ:
$ git switch -c gh-pages
2. ื‘ืื•ืชื• ืขื ืฃ ืฆืจื• ืชื™ืงื™ื” ื—ื“ืฉื” ืขื‘ื•ืจ ื”ืงื‘ืฆื™ื ืฉืœ ื”ื“ืฃ. ืืคืฉืจ ืœื™ืฆื•ืจ ืืช ื”ืคืจื•ื™ืงื˜ ืขื vite.
$ npm create vite@latest gh-pages
3. ืขืจื›ื• ืืช ื”ืงื‘ืฆื™ื ืฉื‘ืชื™ืงื™ื™ื” ื›ื“ื™ ืœื™ืฆื•ืจ ืคืจื•ื™ืงื˜ ืฆื“-ืœืงื•ื— (ืื ื™ ื‘ื—ืจืชื™ ืจื™ืืงื˜ ื•ื˜ื™ื™ืคืกืงืจื™ืคื˜, ืื‘ืœ ืืคืฉืจ ืœื‘ื—ื•ืจ ื›ืœ ื˜ื›ื ื•ืœื•ื’ื™ื™ืช ืฆื“ ืœืงื•ื— ืฉืชืจืฆื•). ืžื” ืฉื—ืฉื•ื‘ ืฉื”ืคืจื•ื™ืงื˜ ื™ื•ื›ืœ ืœื”ื™ื‘ื ื•ืช ืขื npm build ื‘ืœื™ ืฉื’ื™ืื•ืช. 4. ืžืขืœื™ื ืืช ื”ืขื‘ื•ื“ื” ืฉืœื ื• ืœืขื ืฃ ื”ื—ื“ืฉ ื‘ืžืื’ืจ:
$ git add .
$ git commit -m 'created gh page'
$ git push --set-upstream origin gh-pages
5. ืชืงื ื• ืืช ื”ื”ื’ื“ืจื•ืช - ื‘ืงื•ื‘ืฅ vite.config.js ืื• vite.config.ts ื™ืฉ ืœืขื“ื›ืŸ ืืช ืžืคืชื— ื” base ื›ื“ื™ ืฉื™ืชืื™ื ืœื“ื•ืžื™ื™ืŸ ืืœื™ื• ืืชื ื”ื•ืœื›ื™ื ืœื”ืขืœื•ืช ืืช ื”ืคืจื•ื™ืงื˜. ืื ื—ื ื• ื™ื•ืฆืจื™ื ื“ืฃ ื’ื™ื˜ื”ืื‘ ืœืคืจื•ื™ืงื˜ ืงื™ื™ื ื•ื‘ืžืงืจื” ืฉืœื™ ืฉื ื”ืžืื’ืจ ื”ื•ื blog-to-telegram ืœื›ืŸ ืื ื™ ืืฉืชืžืฉ ื‘ืฉื ื”ืคืจื•ื™ืงื˜ ื‘ืชื•ืจ base. ื”ืงื•ื‘ืฅ ืื—ืจื™ ื”ืฉื™ื ื•ื™ ื ืจืื” ื›ืš:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  base: '/blog-to-telegram/',
  plugins: [react()],
})
6. ืฆืจื• ืชื™ืงื™ื” ื—ื“ืฉื” ื‘ืคืจื•ื™ืงื˜ (ืชื—ืช ื”ืชื™ืงื™ื” ื”ืจืืฉื™ืช) ื‘ืฉื .github/workflows ื•ื‘ืชื•ื›ื” ืฆืจื• ืงื•ื‘ืฅ ื‘ืื™ื–ื” ืฉื ืฉืชื‘ื—ืจื• ืขื ืกื™ื•ืžืช yml, ืœืžืฉืœ ืœืงื•ื‘ืฅ ืฉืœื™ ืงืจืืชื™ deploy-gh-page.yml. ืชื•ื›ืŸ ื”ืงื•ื‘ืฅ ื”ื•ื:
* Simple workflow for deploying static content to GitHub Pages *
name: Deploy static content to Pages

on:
  # Runs on pushes targeting the default branch
  push:
    branches: ['gh-pages']

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

* Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages *
permissions:
  contents: read
  pages: write
  id-token: write

* Allow one concurrent deployment *
concurrency:
  group: 'pages'
  cancel-in-progress: true

jobs:
  # Single deploy job since we're just deploying
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Set up Node
        uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: 'npm'
          cache-dependency-path: '**/package-lock.json'
      - name: Install dependencies
        working-directory: ./gh-pages
        run: npm install
      - name: Build
        working-directory: ./gh-pages
        run: npm run build
      - name: Setup Pages
        uses: actions/configure-pages@v3
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v2
        with:
          # Upload dist repository
          path: './gh-pages/dist'
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v2
7. ื“ื—ืคื• ืืช ื›ืœ ื”ืฉื™ื ื•ื™ื™ื ืœืคืจื•ื™ืงื˜:
$ git add .
$ git commit -m 'add workflow'
$ git push
ื›ืขืช ื”ื›ื ืกื• ืœื“ืฃ ื”ืคืจื•ื™ืงื˜ ืฉืœื›ื ื‘ื’ื™ื˜ื”ืื‘ ื•ื‘ื—ืจื• ื‘ื˜ืื‘ Actions. ืœื—ืฆื• ืขืœ ื”ืืงืฉืŸ ื”ื—ื“ืฉ ืฉื™ืฆืจืชื ื•ืื ื”ื›ืœ ืขื‘ื“ ื›ืžื• ืฉืฆืจื™ืš ืืชื ืชืจืื• ืœื™ื“ื” ืกื™ืžืŸ ืฉืœ ื•ื™ ื™ืจื•ืง ืฉืžืกืžืŸ ืฉื”ื™ื ื‘ื•ืฆืขื” ื‘ื”ืฆืœื—ื”. ืœื—ืฆื• ืขืœ ื”ื•ื™ ื”ื™ืจื•ืง ื•ืชื’ื™ืขื• ืœืžืกืš ื”ื”ืจืฆื” ื•ื‘ื• ื™ืฉ ืชื™ื‘ื” ื‘ืฉื deploy ืขื ื”ื ืชื™ื‘ ืœืืŸ ื ืฉืžืจ ื”ื“ืฃ ืฉืœื›ื. ืœื—ืฆื• ืขืœ ื”ืœื™ื ืง ื›ื“ื™ ืœืจืื•ืช ืืช ื”ืขืžื•ื“ ื‘ืื•ื•ื™ืจ.

ToCode - Telegram kanali @tocodeil statistikasi va tahlili