1

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);
1
  • 1
    Consider avoiding any to make errors more explicit - any kinda defeats the purpose of using TS Commented Dec 28, 2020 at 18:49

1 Answer 1

1

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.