Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

ReactNative:Can't perform a React state update on an unmounted component

$
0
0

bug

11:48Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.bug error

intent

I want to use the modal-box to play the video by clicking on the video-image list. So I wrote openVideoFunc to switch video-URL and show/hide modal-box.

code

// Require local imgconst image1 = require('./assets/img/1.jpg')const image2 = require('./assets/img/2.jpg')// Require local videoconst video1 = require('./assets/video/1.mp4')const video2 = require('./assets/video/2.mp4')// array object for img/videoconst videoRes = [{"videoId": 1,"videoUrl": video1,"posterUrl": image1,"title": "test1","describe": "test1......"},...]export default function App() {  const [visible, setVisible] = React.useState(false);  const [videoUrl, setVideoUrl] = React.useState(null)// Video Poster List  const listItems = videoRes.map(item =><TouchableOpacity onPress={() => openVideoFunc(item)} key={item.videoId}><Layout><Image source={item.posterUrl} /></Layout></TouchableOpacity>  )//open video func  const openVideoFunc = (item) => {    setVideoUrl(item.videoUrl) //Switch video url    setVisible(true) //open modal  }  return (<Layout>        {listItems}<Modal visible={visible}><Button onPress={() => setVisible(false)} /> //close modalbox           <VideoPlayer source: videoUrl /> //videoplayer</Modal></Layout>  );}

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>