Posts

Showing posts with the label ReactJS

Using .play() on a React Component

  Using .play() on a React Component React, a popular JavaScript library for building user interfaces, provides various ways to interact with elements and components. One common scenario in web development is playing media, such as videos or audio, within a React component. The .play() method, which is native to the HTML5 <video> and <audio> elements, can be used to control media playback programmatically. 1. Basic Setup To demonstrate how to use the .play() method in a React component, let's start with a simple example using the <video> element. Here's how you can create a React component to play a video when a button is clicked: jsx Copy code import React , { useRef } from 'react' ; const VideoPlayer = ( ) => { const videoRef = useRef ( null ); const handlePlay = ( ) => { if (videoRef. current ) { videoRef. current . play (); } }; return ( < div > < video ref = {videoRef} width = ...

Declarative combination and imperative in ReactJS

When designing an application in react js to improve reusability, I used Tabs, and then passed the Tabs and headers to similar const tabs ={    "tabHeader1": TabContent1,    "tabHeader2": TabContent2  } <SwipableTabs tabs={tabs}> Now, when I had to grant them based on permissions, I was confused. To avoid other problems, I designed the following components: <ProtectedAction> {children} My ProtectedAction component will check permissions and present children based on the permissions. What the reaction implies (declarative). Now, when I see the examples above (such as data-driven tabs), I have to use other examples that I want to get rid of again.