小编use*_*499的帖子

在事件处理程序中调用自定义挂钩

我有一个名为useFetchMyApi包装对 API 端点的 fetch 调用的自定义挂钩。函数钩子接受一个参数,并将其包含在帖子正文中。数据数组输出取决于钩子参数。

在UI上,App组件调用useFetchMyApi一次。随后将调用按钮单击处理程序useFetchMyApi来更新 UI 上的列表。

我的问题:

  1. 我无法调用useFetchMyApi事件处理程序,因为它违反了挂钩规则。
  2. 如何根据 的响应刷新项目列表useFetchMyApi
import React, { useState, useEffect, useRef } from "react";
import "./styles.css";

const useFetchMyApi = (location = "") => {
  const [items, setItems] = useState([]);
  useEffect(() => {
    // let's stimulate the API call with a 2 seconds response time
    setTimeout(() => setItems([location, Math.random()]), 5000);
  }, [location]);
  return { items };
};

export default function App() {
  const locationSelect …
Run Code Online (Sandbox Code Playgroud)

reactjs react-hooks

11
推荐指数
1
解决办法
1万
查看次数

ReflectionClass getDocComment 返回 false

我正在尝试从类中获取文档注释,并且对于我的一生,我不知道为什么 getDocComment() 返回 false。我期待 getDocComment 返回@Whatever。

<?php
/** @Whatever */
class Test {
}

$rc = new ReflectionClass("Test");
var_dump($rc->getDocComment());
Run Code Online (Sandbox Code Playgroud)

输出:布尔值(假)

$ php --version
PHP 5.5.1 (cli) (built: Aug 31 2013 01:32:53) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.2-dev, Copyright (c) 1999-2013, by Zend Technologies
Run Code Online (Sandbox Code Playgroud)

php reflection

5
推荐指数
1
解决办法
1403
查看次数

标签 统计

php ×1

react-hooks ×1

reactjs ×1

reflection ×1