I'm trying to pass a date object as a prop in react native, and access its methods to render data.
The prop is passed as following:
<Task
text={item["text"]}
date={item["date"]}
time={item["time"]}
reminder={item["reminder"]}
completed={item["completed"]}
/>
It is accessed as:
<View>
<View
style={[
styles.item,
completed
? { backgroundColor: "#98CBB4" }
: { backgroundColor: "#CCC9DC" },
]}
>
<View style={styles.ciricleTitle}>
<View style={styles.circular}></View>
<Text style={styles.itemText}>{text}</Text>
</View>
<Text style={styles.itemText}>{console.log(date.date)}</Text>
{/* <Text style={styles.itemText}>{date.getDay()}</Text> */}
</View>
{completed && <View style={styles.line} />}
</View>
i tried expanding the prop with {...item['date']} but it is not working
We have to convert string to date object, You can use
new Date(date).getDay()