如何从reactjs中的navbar.js按钮访问嵌套函数?

问题描述

我想在我的导航栏中添加一个保存按钮,该按钮应该唤起我的savebuttonhandler1函数。但是,savebuttonhandler1函数功能组件(rete.js)中的嵌套函数

Rete.js是一个功能组件,服务于我的网站的一页。它调用一个API(对话流)。导航栏位于每个页面的顶部。

这是组件的层次结构: App.js(父级)-> Navbar.js(子级)

App.js(父级)-> Canvas.js(父级)-> Rete.js(子级)

您知道访问嵌套函数的任何方法吗?我可以使用react上下文吗?

这是我的navbar.js(简体):

const Navbar = (props) => {
  return (
    <div className={root}>
      <AppBar position="absolute" className={root}>
        <Toolbar>
          <img className={img} src={logo} alt={logo} />
          <Typography variant="h4" className={title} component={Link} to="/">
            MyTeachingBot
          </Typography>
                <Fragment>
                  <Button
                    className={createnewButton}
                    component={Link}
                    endIcon={<SaveIcon />}
                    onClick={savebuttonhandler1} --> this is the button where I want to envoke the nested function
                  >
                    Save and Test
                  </Button>
      
                
            ]
          )}
        </Toolbar>
      </AppBar>
    </div>
  );
};

这是rete.js中的嵌套savebuttonhandler1函数

const Rete = (props) => {
   const saveButtonHandler1 = async () => {
     ...some Code}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)