简体   繁体   English

reactjs 中一个组件影响另一个组件

[英]One component affecting another in reactjs

Every url loads three main components: Left panel, center and right panel.每个 url 加载三个主要组件:左面板、中间面板和右面板。 In right panel, we have a button which returns a sub-component CreateForm inside the right panel.在右侧面板中,我们有一个按钮,它返回右侧面板中的子组件 CreateForm。 Left panel contains links which returns individual sub-component to left panel.左面板包含将单个子组件返回到左面板的链接。

Here, the problem is every sub-component of the left panel changes url and thus loads three main components;在这里,问题是左侧面板的每个子组件都会更改 url,从而加载三个主要组件; so if current state of form is open on the right panel and if we select any links in the left panel sub-component, we get the right panel reloaded again so we cannot stay to form.因此,如果当前 state 表单在右侧面板上打开,并且如果我们 select 左侧面板子组件中的任何链接,我们将再次重新加载右侧面板,因此我们无法停留在表单上。

How can I solve that?我该如何解决?

We had use useEffect, localstorage for storing state of the contact form and do form component code inside rightpanel component only(without calling separate component for form on click).我们使用 useEffect 和 localstorage 来存储联系人表单的 state,并仅在右面板组件中执行表单组件代码(无需在单击时为表单调用单独的组件)。 This worked well.这很好用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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