In my app, i am passing some weather data to a component as a prop and I want to have the color of the temp update based on that value. Here is what I did. It seems that react does not always re-render when a prop is changed. How can I make sure that this gets updated every time the prop changes?
const Current = (props) => {
const { weather } = props
const [color, setColor] = useState([])
useEffect(() => {
setColor(tempScheme[weather.current.temp_f])
}, [weather, color])
return (
<Container>
<CardContent>
<Header>
<Typography variant='h6'>Currently</Typography>
<Typography variant='h6'> {formatDate(props.weather.location.localtime)} </Typography>
</Header>
<Weather>
<Typography variant='h5'> {props.weather.current.condition.text} </Typography>
<Typography variant='h2' style={{"color": `rgb(${color})`}}> {Math.round(props.weather.current.temp_f)}° </Typography>
</Weather>
<Location>
<Typography variant='body1'> {props.weather.location.name}, {props.weather.location.region}</Typography>
<Image src={props.weather.current.condition.icon} />
</Location>
</CardContent>
</Container>
)
}e here