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

Make the background blink for 1 second, whenever the state changes [duplicate]

$
0
0

I want the background of the view to be changed based on state , that comes from the API , I want the background of the view to be changed for 1 second whenever the state changes

Here is my code, This is what I tried to do

//*******************************************************

    async componentDidMount() {
    try {
      setInterval(async () => {
        const res = await fetch('https://jsonplaceholder.typicode.com/todos/1');

        const blocks = await res.json();

               if(this.state.a!==blocks.id){ //comparing with initial state which is null
            this.setState({backgroundcolor:"#98fb98"})
        } //I want this to happen for 1 second whenever the state changes


        this.setState({
          panelone: dataPanelone,
          paneltwo: dataPaneltwo,
        })
      }, 2000);


    } catch(e) {
      console.log(e);
    }
   }

Viewing all articles
Browse latest Browse all 28479

Trending Articles



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