我能否确定组件对redux-saga的调用何时结束?

时间:2019-03-20 13:11:13

标签: reactjs redux redux-saga

当组件正在调用redux-saga时,它会尝试显示加载图标,并在完成对redux-saga的调用后隐藏加载图标。

ForEach-Object {
    $HTTP_Request = [System.Net.WebRequest]::Create($siteURL + $_)

    try {
        $HTTP_Response = $HTTP_Request.GetResponse()
    }
    catch [System.Net.WebException] {
        # HTTP error, grab response from exception
        $HTTP_Response = $_.Exception.Response
    }
    catch {
        # Something else went horribly wrong, maybe abort?
    }
    finally {
        # Grab status code and dispose of response stream
        $HTTP_Status = [int]$HTTP_Response.StatusCode
        $HTTP_Response.Dispose()
    }

    "$_ - $HTTP_Status"
}
// at component
const app: FunctionComponent<IProps> = ({ location, history }) => {
  ...
  const [isLoading, setLoading] = useState(false);
  useEffect(() => {
    setLoading(true);
    ItemsActions.getItems(); <- this line is redux-saga call request

    // I want the redux saga call to be completed and the loading to end here!
    setLoading(false);

  }, []);
  ...
}

1 个答案:

答案 0 :(得分:1)

只需让您的减速器的switch语句包含GET_ITEMS_SUCCESS,然后在触发时将装入变量更改回false。不要忘记对任何错误状态执行相同的操作。

相关问题