porosh
porosh

Reputation: 83

Getting error when destructure value from state in TypeScript

enter image description here

When I tried to destructure the notification_menu value am getting the error like this

am using Redux for state management

enter image description here

import React, { Suspense,Component } from 'react';
import { Switch, Route } from "react-router-dom";
import { connect } from 'react-redux';
import { NotificationMenu } from "./Redux/NotificationMenu/nof_selector";
 class App extends Component {
  state = {
    navOpen: false,
  };
  NavCall = () => {
    this.setState({ navOpen: !this.state.navOpen });
  };
   render() {
     console.log(this.props.notification_menu);
    const { navOpen } = this.state;
    const NavOpenStyleMargin = navOpen ? { marginLeft: "250px" } : {};
    return (
      <div>
    </div>
    )
  }
}
const mapStateToProps = (state:any) => {
  return {
    // userID: selectCurrentUser(state),
    // account_menu: AccountMenu(state),
    notification_menu: NotificationMenu(state),
  };
};
export default connect(mapStateToProps,null)(App);

Upvotes: 1

Views: 107

Answers (1)

buzatto
buzatto

Reputation: 10382

when using typescript you need to declare props and state types to your class component like:

interface IProps {
  notification_menu: string // define what type notification_menu is
}

interface IState {
  navOpen: boolean
}

class MyComponent extends React.Component<IProps, IState> {
  // code here
}

Upvotes: 1

Related Questions