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

  

如果您觉得本文对你有用,不妨帮忙点个赞,或者在评论里给我一句赞美,小小成就都是今后继续为大家编写优质文章的动力,百小僧拜谢! 欢迎您持续关注我的博客:)
原文地址:https://www.cnblogs.com/baiqian/p/15104905.html