简体   繁体   中英

How to force component to reender in react-native, when click in child component button

我有一个包含3个产品组件的购物车组件,当我通过单击“删除”按钮从购物车中删除产品时,我希望该购物车组件能够提供实时的删除预览,仅显示剩余的产品

While there are many ways, you need to use a state management implementation. You could try redux or mobx. There are other alternatives too. Mobx could get you started quickly if the application is not complex .

There could be two possibilities to solve this.

  1. Redux(or you can use other library). This will automatically update the component if the props changes

  2. If you are not using libraries like redux to manage store of your application then you can play by passing a method from your component to your cart and calling this method in your cart when necessary action is been done. Inside this method just toggle a boolean variable of your state or you can do anything you wish to like passing the data as param from the cart and utilising that value in your component; this may refresh your component.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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