I am trying to give a conditional colour to a component in react if the type is like it will be green or dislike it will be red. This would work in javascript but with using typescript I am getting the error:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ like: string; dislike: string; }'. No index signature with a parameter of type 'string' was found on type '{ like: string; dislike: string; }'.
I am fairly new to typescript in react so I am not too sure how to solve this so any help would be great!
import React from "react";
import {Text, View} from "react-native";
import {styles} from "./styles";
const COLORS = {
like: '#00edad',
dislike: '#ff006f',
}
const Choice = ({type} : {type : string}) => {
const color = COLORS[type];
return (
<View style={[styles.container, {borderColor: color}]}>
<Text style={[styles.text, {color}]}>{type}</Text>
</View>
)
}
export default Choice;