This is my code and the error I am getting is in attached picture what is the error in my code. The Purpose of my code is that whenever I click Add new box button a box with random color will be displayed below the previously created box.
import {styleSheets,View,Text,Button,FlatList} from 'react-native';
const ColorF= () => {
const[colors,setColor] = useState([]);
//console.log(colors)
<View>
<Button title = "Add a new box"
onPress = {()=>{
setColor([...colors,randomRgb()])
}}
/>
</View>
return(
<FlatList
data = {colors}
KeyExtractor = {(colors)=>colors.item}
renderItem = {({item})=>{
return <View style ={{height:100,width:100,backgroundColor:randomRgb(item)}}>
}
}
/>
);
}
const randomRgb=()=>{
const red = Math.floor(Math.random()*256);
const green = Math.floor(Math.random()*256);
const blue = Math.floor(Math.random()*256);
return `rgb(${red},${green},${blue})`;
};
export default ColorF;

