'Update component style based on state in React Native

I want to update the style for my text field to show whether this is selected or not. Here is my code sample.

<Text style={isOptionValueSelected(optionValue.value_index) ? styles.configOptionValueSelectedText : styles.configOptionValueText}>{optionValue.extension_attributes.swatch_value}</Text>

const isOptionValueSelected = useCallback((value_index) => {
    let optionIndex = false;
    for (var i = 0; i < selectedConfigOptions.length; i++) {
        if (selectedConfigOptions[i].option_value == value_index) {
            return true;
            break;
        }
    }
    return optionIndex;
},[selectedConfigOptions])

When I click on the text box my state is updating fine but the visible part that need to fix. Would anyone please help with this?

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source