How to change color of the JSON message based on status code with ReactJS
try adding another state
const [isError, setIsError] = useState(false)
...
if (response.data.statusCode == 200) {
setLoading(false)
setMessage(response.data.msg)
setIsError(false)
}
else {
setLoading(false)
setIsError(true)
setMessage(response.data.msg)
}
then in div that displays the message.
<div style={color: isError ? 'red' : ''}>{message}</div>