简体   繁体   中英

Why can't functions call each other inside my <App /> component in React

I have the following two functions inside my <App /> component and they are placed just before the render() method. I would like open_theme_FUNCTION to be able to call new_or_open_so_clear_workspace_FUNCTION but it is out of scope and not declared. Why is this?

    new_or_open_so_clear_workspace_FUNCTION = (that) => {
      that.setState({
        start_show_or_hide : false,
        application_menu_show_or_hide : false,
        workspace_background : "white"
      });
    }

    open_theme_FUNCTION = () => {
      console.log("Opening a project")
      new_or_open_so_clear_workspace_FUNCTION(this)
      // code
    };

I expect it to be a class component, so you only have to use this .

open_theme_FUNCTION = () => {
   console.log("Opening a project")
   this.new_or_open_so_clear_workspace_FUNCTION(this)
   // code
};

And you also should avoid passing around this . Your example should work without doing that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM