|
|
@@ -1,7 +1,7 @@
|
|
|
import React, { useState, useEffect } from 'react'
|
|
|
import { View, Text, ScrollView } from '@tarojs/components'
|
|
|
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
|
-import Taro from '@tarojs/taro'
|
|
|
+import Taro, { useRouter } from '@tarojs/taro'
|
|
|
import { Navbar } from '@/components/ui/navbar'
|
|
|
import TDesignSearch from '@/components/tdesign/search'
|
|
|
import GoodsList from '@/components/goods-list'
|
|
|
@@ -14,17 +14,16 @@ type GoodsResponse = InferResponseType<typeof goodsClient.$get, 200>
|
|
|
type Goods = GoodsResponse['data'][0]
|
|
|
|
|
|
const SearchResultPage: React.FC = () => {
|
|
|
- const [keyword, setKeyword] = useState('')
|
|
|
- const [searchValue, setSearchValue] = useState('')
|
|
|
const { addToCart } = useCart()
|
|
|
|
|
|
- // 获取页面参数
|
|
|
- useEffect(() => {
|
|
|
- const params = Taro.getCurrentInstance().router?.params
|
|
|
- const searchKeyword = params?.keyword || ''
|
|
|
- setKeyword(searchKeyword)
|
|
|
- setSearchValue(searchKeyword)
|
|
|
- }, [])
|
|
|
+ // 使用useRouter钩子获取路由参数
|
|
|
+ const router = useRouter()
|
|
|
+ const params = router.params
|
|
|
+ const searchKeyword = params?.keyword || ''
|
|
|
+
|
|
|
+ // 直接使用路由参数,无需useEffect
|
|
|
+ const [keyword, setKeyword] = useState(searchKeyword)
|
|
|
+ const [searchValue, setSearchValue] = useState(searchKeyword)
|
|
|
|
|
|
const {
|
|
|
data,
|