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);
    

      

    如果您觉得本文对你有用,不妨帮忙点个赞,或者在评论里给我一句赞美,小小成就都是今后继续为大家编写优质文章的动力,百小僧拜谢! 欢迎您持续关注我的博客:)
  • 相关阅读:
    递归与分治4
    递归与分治3
    递归与分治2
    递归与分治1
    枚举与递推3
    枚举与递推2
    求编译器中数的最值(c++)
    移动小球链表实现
    阶乘的精确值
    while((c = getchar()) != EOF)(键盘输入问题)
  • 原文地址:https://www.cnblogs.com/baiqian/p/15104905.html
Copyright © 2011-2022 走看看