简体   繁体   English

如何使用React.js在Redux容器中更改onClick元素?

[英]How to do onClick element change in Redux a container with React.js?

I already saw a similar question from someone else here and the answer is pretty clear. 我已经在这里从其他人那里看到了类似的问题,答案很明确。 Yet, if you're working with in a redux container, the states turn into props through the mapStateToProps function. 但是,如果您在redux容器中使用状态,则通过mapStateToProps函数将状态变成道具。

How is it then correct to proceed if I want eg my text-div to turn into an input, when I click or double-click on it? 如果我想例如将我的text-div变成输入时,单击或双击,该如何正确进行? I don't have any code yet, I'm wondering about the theory. 我还没有任何代码,我想知道这个理论。

The components get store state data passed in as props, but they can also have their own state. 组件获取作为道具传入的存储状态数据,但它们也可以具有自己的状态。 So in your case, your component would use it's own state to handle the toggling of div to input . 因此,在您的情况下,您的组件将使用其自身的状态来处理divinput的切换。 If for some reason you wanted it to be saved in the store instead, you would fire off an action to toggle the view and then use the prop from the store in your render method. 如果出于某种原因您希望将其保存在商店中,则可以触发一个操作来切换视图,然后在渲染方法中使用商店中的道具。

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

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