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

Can't stop re-render for color background with useMemo React?

$
0
0

On each re-render it generates a new color. How do I cache the first color it gets initialized and re-use it each now?

  const backgroundColor = newBackgroundColor(); // some random color  const background = React.useMemo(() => {    return backgroundColor;  }, []);  const buttonStyle: React.CSSProperties = {          background: background,  };  return (<button style={buttonStyle}>  )

Viewing all articles
Browse latest Browse all 6295

Trending Articles



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