我正在尝试将我所有的类组件转换为功能组件。我正在使用redux来处理状态,但是我对功能组件还不太熟悉。如何将该Class组件转换为功能组件?
InputMethodInfo
答案 0 :(得分:2)
好吧,要使用钩子将基于类的组件转换为功能组件,请对类组件中fold
中的每个字段使用this.state
调用。
由于功能组件中存在useState
个剂量,因此可以使用componentDidMount
来代替useEffect
,componentDidMount
和componentDidUpdate
。
所以该组件看起来像这样
componentWillUnmount
答案 1 :(得分:1)
以下是您的代码的功能组件:
Regex onlyAlphanumericAndDash = new Regex("[^a-zA-Z0-9 -]");
. . .
foreach (string line in doc1StrArray) // doc1StrArray populated in FindAndStorePhrasesFoundInBothDocs()
{
trimmedLine = line;
// first replace the "long dash" with a space (otherwise the dashed words run together:
// "consecrated—we" becomes "consecratedwe"
trimmedLine = trimmedLine.Replace("—", " ");
trimmedLine = onlyAlphanumericAndDash.Replace(trimmedLine, "");
string[] subLines = trimmedLine.Split();
foreach (string whirred in subLines)
{
if (String.IsNullOrEmpty(whirred)) continue;
_whirred = whirred.Trim();
iWordsInDoc1++;
slAllDoc1Words.Add(_whirred);
if (IgnoreWord(_whirred)) continue;
InsertIntoWordStatsTable(_whirred, 1, 0);
}
}