我想为我的事件处理程序使用一个类型,而不是使用任何类型,任何人都可以帮助我吗?这是我正在尝试重构的代码:
const MyComponent = () => {
const handleBtnClick = (e: any) => {
e.stopPropagation();
//**Some Code**
}
return <CustomButton onClick={handleBtnClick} />
}
Run Code Online (Sandbox Code Playgroud) 我在 Wordpress 中创建了一个自定义休息路线,它采用产品类别 ID,并将发送属于该类别的产品。
我的问题是我无法找到一种方法来在我的自定义循环中获得可变产品的最低和最高价格。
谁能帮我解决这个问题?谢谢
我试图使用变化价格,get_variation_prices()但似乎我错过了一些东西。
add_action( 'rest_api_init' , 'wt_rest_api');
function wt_rest_api(){
register_rest_route('wtrest','products',array(
'methods' => WP_REST_SERVER::READABLE,
'callback' => 'wtProductResults'
));
}
function wtProductResults($data){
$products = new WP_Query([
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id', //can be set to ID
'terms' => $data['cat'] //if field is ID you can reference by cat/term number
)
)
]);
$productsResults = [];
global $woocommerce;
global $product;
$currency = get_woocommerce_currency_symbol();
while($products->have_posts()){
$products->the_post();
$product_cat = get_term( $data['cat'], …Run Code Online (Sandbox Code Playgroud) 在我的第一个Next.js项目中,我有一个在服务器端呈现的文章组件。我想从客户端获取文章标签,否则我会得到太多 DOM 元素。所以这就是我想出的:
const ArticlesPage = () => {
const [tags, setTags] = useState([])
const { isLoading, isError, data, error } = useQuery('tags', getTags, {
onSuccess: () => setTags(data)
}
//...
})
console.log('tags are:', tags)
return (
<>
...
{!isLoading && !isError &&
<TagsComponent tags={tags} />
}
{isLoading &&
<div> Loading tags...</div>
}
{isError &&
<div> Error fetching tags</div>
}
</>
Run Code Online (Sandbox Code Playgroud)
问题是标签异想天开地呈现在文章页面上,也就是说,当我刷新页面时,它们不会显示,但当我重新关注页面时,标签会显示。我也没有看到任何Loading或Error正在渲染。所以我很困惑这里发生了什么?
我怎样才能解决这个问题?
javascript ×2
reactjs ×2
next.js ×1
php ×1
react-query ×1
typescript ×1
woocommerce ×1
wordpress ×1