javascript - React 我无法关闭价格弹出窗口

标签 javascript reactjs

我正在构建 React 应用程序,但无法关闭价格弹出窗口。我昨天一整天都尝试了一切,但无法解决这个问题。谁能帮我找出错误吗?

我试图做的是,当您单击每个证券列表中的“价格”按钮时,将打开包含价格列表的弹出窗口。您可以在列表中输入新价格。然后,当您点击关闭按钮时,窗口将关闭,并且每个证券中的证券列表和价目表都会更新。

您可以在https://codesandbox.io/s/github/kikidesignnet/caissa查看我的React应用程序.

最佳答案

根据您的代码逻辑,您的price按钮应该打开另一个组件 <PriceForm>但你没有通过任何toggle方法来关闭它,所以你只需要传递 togglePricePopup作为 Prop (我称之为 onClose ),然后在你的 handleFormSubmit 中调用它:

SingleSecuritybox/index.js

{this.state.showPricePopup ? (
  <PriceForm
    pricelist={this.props.price}
    editCurrentPrice={this.editCurrentPrice}
    onClose={this.togglePricePopup} // new prop
  />
) : null}

PriceForm/index.js

handleFormSubmit = e => {
  // prevents page refreshes on submission
  e.preventDefault();

  // code...

  // passed prop from SingleSecuritybox
  this.props.onClose();
};

<强> codeSandbox

关于javascript - React 我无法关闭价格弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60974582/

相关文章:

javascript - 自动选择加入 cookie 的浏览器插件 - 欧盟 cookie 法

reactjs - 有没有办法在 React-Bootstrap 中设置自定义断点

reactjs - Webpack 热重载在错误输入错误时停止

javascript - 如何获取自定义 React Babel pragma 将字符串作为参数而不是函数传递

javascript - 如何使数组的每个池只能分配一次

javascript - 简单对象文字的最佳实践 : using "that" or the object's name?

javascript - jQuery 导航添加事件类

javascript - 自定义单元格表 react 虚拟化

javascript - 鼠标悬停在父级上时自动子级高度

javascript - Sequelize 更新与关联