class FoodPost extends React.Component<Props> { constructor(props: Props) {…
- User
class FoodPost extends React.Component { constructor(props: Props) { super(props); this.state = { expanded: false, timeAgo: getTimeAgo(props.data.date) }; } handlePress = () => { console.log("pressed lol"); // this.setState(prevState => ({ expanded: !prevState.expanded })); } render() { const { addMessage, data, theme, ...rest } = this.props; const { timeAgo } = this.state; Property 'timeAgo' does not exist on type 'Readonly<{}>'.ts(2339)
- Assistant
The error you're seeing is because TypeScript doesn't recognize
timeAgoas a property on the component's state. To resolve this, you need to define the type for the component's state in your component. Here’s how you can do it.