I made a function that renders out a different backgroundColor depending on the value.
const backgroundColorResolver = () => {
allQuestions.map((aq) => {
if (aq.averageAnswerValue <= 4) return "#EE7362";
if (aq.averageAnswerValue > 4 && aq.averageAnswerValue < 7)
return "#FDCF5B";
return "#068466";
});
};
And under return in the tsx I do:
<View style={questionAverageResultStyling.indexContainer}>
{allQuestions.map(({ averageAnswerValue, key }) => (
<View
style={{
backgroundColor: `${backgroundColorResolver}`,
margin: "0.5",
width: "100%",
height: "25px",
}}
>
<Text style={questionAverageResultStyling.indexText} key={key}>
{averageAnswerValue}
</Text>
</View>
))}
</View>
However, I get error message "Cannot read property 'value' of null". Specifically in style={{ backgroundColor: ${backgroundColorResolver}} Does anyone know why and how to render out this function in style with the other styles (margin, width, height)? Let me know if information is missing and I will add it.