使用Ref访问功能组件内部的功能。 (我正在使用expo和redux)

时间:2020-09-30 23:50:23

标签: react-native redux expo ref react-functional-component

将Ref与类组件一起使用时,可以像这样import csv import requests from bs4 import BeautifulSoup realtor_data = [] for page in range(1, 6): print(f"Scraping page {page}...") url = f"https://www.realtor.com/realestateagents/phoenix_az/pg-{page}" soup = BeautifulSoup(requests.get(url).text, "html.parser") for agent_card in soup.find_all("div", {"class": "agent-list-card clearfix"}): name = agent_card.find("div", {"class": "agent-name text-bold"}).find("a") number = agent_card.find("div", {"itemprop": "telephone"}) realtor_data.append( [ name.getText().strip(), number.getText().strip() if number is not None else "N/A" ], ) with open("data.csv", "w") as output: w = csv.writer(output) w.writerow(["NAME:", "PHONE NUMBER:", "CITY:"]) w.writerows(realtor_data) 一样将ref传递给子组件,然后可以通过<InputModal ref={ ref => this.modalRef=ref} />来访问其方法,功能组件如何做到这一点?我正在通过redux转发Ref,并像使用类组件一样导出组件。

this.modalRef.methodName()

我目前在expo和redux上使用react-native。

0 个答案:

没有答案