2

I want to show local video as fit in ReactJS App. And trying to width as 100%. But how to declare this style in React?

React Component

componentDidMount() {
  Video.createLocalVideoTrack().then(track => {
     const localMediaContainer = this.refs.localMedia;
     localMediaContainer.appendChild(track.attach());
  });
}

render () {
  return (
      <div ref='localMedia' />
  )
}

The Result:

<div>
  <video autoplay=""></video>
</div>

The video element is created by twilio track automatically (container.appenChild). And I want to define css style for this element.

This works in HTML/JS:

div#local-media {
      width: 100%;
      height: 220px;          
      margin: 0 auto;

  div#local-media video {
    max-width: 100%;
    max-height: 100%;
    border: none;
  }

In React:

const styles = theme => ({
    localMedia: {
        width: '100%',
        height: 220,         
        margin: '0 auto'

    }
});

How can I declare for child element, div#local-media video in react?

Or is there another solution to stretch media to local-media div?

Update 1: element generated by Twilio code with appendChild..

Update 2

I guess I found a solution? It's working

render() {
  return (
    <style jsx>{`
      video {
        max-width: 100%;
        max-height: 100%;
      }
    `}
    </style>

    <div ref='localMedia' />
  )
}
RedLEON
  • 281
  • 2
  • 7
  • 19

1 Answers1

0

Since you are using styles and themes, from which I can expect you are using Material UI in react , then you should use the object classes as per the documentation (https://material-ui.com/customization/themes/).

So the code should be :

<div class={props.classes.localMedia}>
   <video autoplay=""></video>
</div>

you can try doing this.

Ashwamegh
  • 168
  • 8
  • Yes I'm using MateriaUI. localMedia style is working for div element but not the child element, video. – RedLEON Dec 06 '18 at 11:21