提问人:Pedro-Goncal 提问时间:11/16/2023 更新时间:11/16/2023 访问量:27
React Native - SyntaxError:RegExp 无效:在输入上键入“(”时括号内的表达式未关闭)
React Native - SyntaxError: Invalid RegExp: Parenthesized expression not closed when typing "(" on Input
问:
我在我的 react native 应用程序上遇到了一个令人沮丧的错误。
我有一个具有 TextInput 的组件,用于通过 API 搜索内容。现在一切正常,直到我们的一位客户搜索了以下内容
"14-12(“,输入”(“时立即崩溃
我在控制台上遇到的错误如下:
SyntaxError:无效的正则表达式:括号内的表达式未关闭
这是处理搜索的代码:
const [searchTerm, setSearchTerm] = useState("");
//============================================================
//Delay on call search
//============================================================
useEffect(() => {
const delayDebounceFn = setTimeout(() => {
(async () => {
await handleSearch(searchTerm);
})();
}, 500);
return () => clearTimeout(delayDebounceFn);
}, [searchTerm]);
//============================================================
//Handle Search
//============================================================
const handleSearch = async (searchTerm) => {
const headerOption = {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${user.token}`,
},
};
setIsSearchLoading(true);
axiosInstance
.post(
`/rest/V2/search`,
{ book_id: bookSku, search_term: searchTerm.toString() },
headerOption
)
.then((response) => {
// console.log(response);
if (response.data.length > 0) {
setSearchResults(response.data[1]);
}
setIsSearchLoading(false);
})
.catch((error) => {
setIsSearchLoading(false);
console.log(
"Error fetching the search from the server SectionScreen",
error
);
});
};
<TextInput
autoFocus={true}
style={styles.searchInput}
placeholder="Enter Search Term"
onChangeText={(value) => setSearchTerm(value.toString())}
value={searchTerm}
returnKeyType="done"
/>
有人知道可能有什么问题吗?
谢谢!
React Native:“0.71.8”
“反应”:“18.2.0”
“博览会”:“^48.0.0”
答: 暂无答案
评论