简体   繁体   中英

how to resovle multiple refs in react hooks

I want to set dynamic ref in hooks component, but it seems not support in react hooks.

 coupons.map((item: TCouponItem, index: number) => (
                                        <CouponItem
                                            couponItem={item} key={`received${index}`}
                                            ref={`received${index}`}
                                            refName={`received${index}`}
                                            onDescClick={(refName: string) => { onDescClick(refName); }}
                                        />))

Does it any ways to relize this

You can't create ref by simply writing ref=myref . You first need to instantiate the ref with const ref = useRef(null) . Then you can add ref={ref} to the 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