|
 |
|
ติดปัญหาเกี่ยวกับการกด setMute video ในภาษา react.js |
|
 |
|
|
 |
 |
|
คือผมเเบ่งหน้าออกเป็น 3 หน้า หลักๆ ได้เเก่ หน้า App.js , Navbar.js , video.js โดยในฟังก์ชัน setMuted จะอยู่ในหน้า Navbar ซึ่งเมื่อกด setMuted อยากให้ ส่งต่าไปยังหน้า video ตรงตัวเเปร muted={muted} ให้เปลี่ยนเป็น true หรือ false ผมเคยเขียนเเบบ jquery ซึ่งมันสามารถอ้างอิงจากพวก id ได้ เเต่พอมาปรับเขียนเป็น react.js ไม่ร้ว่าจะต้องเขียนอย่างไรเพื่อให้ส่งค่าไปคครับ
code หน้า App.js
Code (PHP)
import React, { useState, useEffect } from "react";
import Video from './Video';
import Navbar from './Navbar';
import './navbar.css';
function App() {
const [videos, setVideos] = useState([]);
return (
<div className="grid row rowx h-100 content">
<Navbar/>
{
videos.map((video) => {
return (
<Video
ID={video.ID}
source={video.source}
/>
)
})
}
</div >
);
}
export default App;
code หน้า Navbar
Code (PHP)
import React, { useState } from 'react'
import VolumeUpIcon from '@material-ui/icons/VolumeUp';
import './navbar.css';
export default function Navbar() {
const [volum, setVolum] = useState(false);
const [muted, setMuted] = useState(false);
const handleFullscreen = event => {
if (muted === true) {
setMuted(false);
setVolum(false);
} else {
setMuted(true);
setVolum(true);
}
};
return (
<div className="navbar filter-button-group ">
<VolumeUpIcon className="volumicon" id="mut1" onClick={handleFullscreen} />
</div>
)
}
code หน้า video
Code (PHP)
import React, { useRef, useState, useEffect } from 'react';
function Video({ ID, source}) {
const videoRef = useRef(null);
return (
<div className="grid-item col-12 fullcard item_content bike section_tv">
<div className="d-flex align-items-end flex-column w-100 h-100">
<video
className="position-absolute section-background video"
autoPlay
preload={preload}
muted={muted}
loop
ref={videoRef}
src={source}>
</video>
</div>
</div>
)
}
export default Video;
Tag : PHP, JavaScript, Node.js

|
|
 |
 |
 |
 |
Date :
2021-06-03 19:45:27 |
By :
worapong39 |
View :
599 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
JS frameworks ใหม่ๆ กำลังถูกขับเคลื่อน เริ่มมีมาเรื่อยๆ 
ผมลองคัดวางแล้วไม่ผ่าน ขึ้น identifier xxx ...already declared และ/หรือ ขึ้นหน้าว่าง หรือ useState not defined หรืออื่นๆ. สรุป คือยังไม่เห็นหน้าตาของปุ่มที่ว่าเลย เลยเทสอีเวนต์ให้ไม่ได้ ถ้าต้องการคำตอบบอกข้อมูลให้ครบ อย่าง
1. React version
2. index.js
3. โค้ดของไฟล์ import ที่เกี่ยวข้องทั้งหมด
4. Error ต่างๆ ขึ้นว่าอะไร นำมาให้หมด
5. เครื่องมือที่ใช้พัฒนา
6
7
8
9 .....
|
 |
 |
 |
 |
Date :
2021-06-04 09:56:32 |
By :
พญามัจจุราช |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าเป็น JS-Library ต้องไปดู document เกี่ยวกับ Props (parent => child), Emit (child => parent) 2 ตัวนี้ครับ เพื่อส่งค่าผ่านไป Components ที่ต้องการ
|
 |
 |
 |
 |
Date :
2021-06-04 18:10:23 |
By :
Genesis™ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|