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' />
)
}