zoukankan      html  css  js  c++  java
  • React 页面开发服务规范抽象

    import React, { useReducer, useContext } from "react";
    import { useFetch } from "use-http";
    import { TicketContext as ProviderContext } from "../../components/home/Tickets.service";
    
    // define initial state
    const initialState = {
      ticketId: 0,
      ticket: {},
      initData: {},
    };
    
    // difine reducer
    const reducer = (state, { type, ...action }) => {
      return actions[type](state, action);
    };
    
    // export actions
    const actions = {};
    
    // export and define only hooks
    export default function usePage() {
      const [state, dispatch] = useReducer(reducer, initialState);
      const fetch = useFetch({});
      const ProviderValue = useContext(ProviderContext);
    
      return [state, dispatch, fetch, ProviderValue];
    }
    
    // export and define only Context
    export const Context = React.createContext(null);
    

      

    如果您觉得本文对你有用,不妨帮忙点个赞,或者在评论里给我一句赞美,小小成就都是今后继续为大家编写优质文章的动力,百小僧拜谢! 欢迎您持续关注我的博客:)
  • 相关阅读:
    github的使用
    QPalette的用法
    QTimer的用法
    QStatusBar的用法
    QWhatsThis的用法
    QString::​arg的用法
    qt中ui的 使用介绍
    安全协议IPSEC
    安全协议ssl
    对称加密和非对称加密
  • 原文地址:https://www.cnblogs.com/baiqian/p/15104905.html
Copyright © 2011-2022 走看看