简体   繁体   English

如何使用Reactjs使用组件的状态填充模式形式?

[英]How to populate modal form with a component's state with Reactjs?

I have many child React components that are rendered from a parent Component and upon clicking the name of each one, I'd like to be able to edit the state of the particular component that was clicked, however I am not sure how to best "pass" the current state into the modal so that they can be edited in the form on the modal. 我有许多从父组件渲染的子React子组件,单击每个组件的名称后,我希望能够编辑被单击的特定组件的状态,但是我不确定如何最好地“将当前状态传递给模态,以便可以模态上的形式对其进行编辑。

I have seen implementations where the modal fields are set with jquery (.val()) after the click, which does not seem like the idiomatic react way to do this. 我已经看到了在单击后使用jquery(.val())设置模式字段的实现,这似乎不是惯用的反应方式。

How should I prepopulate the modal fields from the particular component and where should the modal be rendered exactly? 我应该如何从特定组件中预填充模态字段,模态应在哪里准确呈现?

Depending on the modal you use, you should simply populate those values using props into a modal component. 根据您使用的模态,您应该简单地使用prop将这些值填充到模态组件中。 You can create a more generic modal component and feed this modal your props, or a specific modal if you don't think you could create a generic one that fits more use cases than this specific one. 您可以创建一个更通用的模态组件,并为您的道具提供该模态,如果您不认为可以创建比该特定模样更适合用例的通用模态组件,则可以使用特定模态。 It's hard to give examples of code without seeing/knowing which one you use, but below link of react-bootstrap's implementation of the modal might help you! 在不知道/不知道使用哪一个代码的情况下很难给出代码示例,但是在react-bootstrap的modal实现中,下面的链接可能会对您有所帮助!

React-bootstrap's implementation of the Bootstrap modal. React-bootstrap对Bootstrap模式的实现

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

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